控制台输入错误java.lang.NullPointerException [英] Console Input error java.lang.NullPointerException

查看:252
本文介绍了控制台输入错误java.lang.NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过代码:

import java.io.Console;
public class Default
{
    public static void main(String args[]) throws IOException
    {
        Console console = System.console();
        String testing = console.readLine("Enter Name: ");
        System.out.println("Entered Name: "+ testing);
    }
}

进入异常并出现以下错误:

未找到来源。 NullPointerException

goes to exception with following error:
Source not found. NullPointerException

我正在使用Eclipse Juno EE进行调试..!

I am using Eclipse Juno EE for debugging .. !

和上述代码的参考链接为此处

And the reference link for above written code is here

推荐答案

您是否正在运行您的程序,因为 console.readLine 返回

Are you running your program from an ide as console.readLine returns null when used from an IDE.

有关详细信息,请参阅此内容

如果从命令行运行它不会收到此错误。

If you run it from command line you will not get this error.

这篇关于控制台输入错误java.lang.NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆