Skip to content

Variables, Data Types and Operators section - Activity 1 example needs fix #7

@shashankshet

Description

@shashankshet

As we're using Intellij idea for development, the example provided in Activity 1 of section Variables, Data Types and Operators is failing with error:
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.io.Console.readLine()" because "console" is null at VariablesDataTypesOperators.MyFirstInput.main(MyFirstInput.java:9)

Reason for error:
The System.console() method returns a Console object if the JVM is started from a console and not from an IDE or a non-interactive environment. In an IDE or certain execution environments, this method may return null

Proposed solustion:
If you want your code to work in a variety of environments, including IDEs, you should consider using the Scanner class or another input method that is not dependent on the availability of a console object.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions