本文介绍了控制台的readLine()中的NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此:

Console c = System.console();
        String readline;
        String u = c.readLine("%s", "args");

引发 NullPointerException。但是该方法是:

 public String readLine(String fmt, Object... args)

为什么会引发此异常?

推荐答案

Console c = System.console();

c 是否为空?

返回与当前Java
虚拟机关联的唯一控制台对象
(如果有的话)。

Returns the unique Console object associated with the current Java virtual machine, if any.

返回:系统控制台,如果有的话,
否则为空

Returns: The system console, if any, otherwise null.

这篇关于控制台的readLine()中的NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 18:24
查看更多