如何正确使Java调试器在vs代码中工作

时间:2019-02-15 19:31:50

标签: java visual-studio

每当我尝试调试这段代码时,调试控制台都会显示以下消息(或任何其他代码):

Exception in thread "main" java.lang.NullPointerException   at test.main(test.java:7)

我已经安装了所有必需的扩展程序(Red Hat和Java扩展包对Java™的语言支持),并在计算机上的路径中添加了Java。我也可以编译并运行文件。如何使调试器正常工作?

import java.io.Console;

public class Treestory {

    public static void main(String[] args) {
        Console console = System.console();
        String ageAsString = console.readLine("How old are you?");
        int age = Integer.parseInt(ageAsString);
        if (age < 13) {console.printf("Sorry you are not old enough");
        System.exit(0);
    }
        String name = console.readLine("Enter a name:  ");
        String adjective = console.readLine("Enter an adjective:  ");
        String noun;
        do {noun = console.readLine("Enter a noun:  ");
        if(noun.equalsIgnoreCase("Dork") || noun.equals("jerk")) { console.printf("Inapropriate Language");
        }
        }      

        while (noun.equals("Dork") || noun.equals("jerk"));

        String adverb = console.readLine("Enter an adverb:  ");
        String verb = console.readLine("Enter a verb ending with -ing:  ");
        console.printf("%s is a very %s %s, she is always %s %s", name, adjective, noun, adverb, verb );
        /*  Some terms:
            noun - Person, place or thing
            verb - An action
            adjective - A description used to modify or describe a noun
            Enter your amazing code here!
        */

    }   
 }

0 个答案:

没有答案