简体   繁体   中英

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!

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

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

public static void main(String[] args) {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM