Gianna Caruso
Gianna Caruso

Reputation: 113

Null Pointer Exception in Dr. Java

    import java.util.Scanner;
    public class Question_11 {

        public void main(String[] args) {


        double RATE = 35.75;
        double Wages;
        double Hours;

        Scanner keyboard = new Scanner(System.in);


        System.out.print("Please enter the number of hours worked: ");
        Hours = keyboard.nextDouble();

        //calculate wages
        Wages = Hours * RATE;

        System.out.println("The calculated wages = " + Wages);

    }

}

This is my code, I keep getting this error:

java.lang.NullPointerException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)

It compiles but will not run.

Thank you in advance!

Upvotes: 0

Views: 524

Answers (1)

Reimeus
Reimeus

Reputation: 159804

This is Dr. Java's annoyingly nondescript stacktrace which occurs when the main method is not found by the VM.

I.e.: Add the static keyword to the main method so that the application has a valid entry point

public static void main(String[] args) {

Upvotes: 5

Related Questions