繁体   English   中英

NullPointerException无法解析为变量

[英]NullPointerException cannot be resolved to a variable

我对仅接受整数的对话框使用不正确的输入尝试/捕获。 TA告诉我,我需要导入一些东西。 我试过了,但在第8行仍然收到相同的错误:

import java.lang.NullPointerException; //put this where it should be


try
{
    buttons.rotatebutton(); //method I created
}
catch (NumberFormatException | NullPointerException e)
{
    System.out.println("Please type a number");
    if (e == NullPointerException) //ERROR OCCURS HERE
    {
        System.out.println("User cancelled");
    }
}

谁能阐明一些想法?

如果要检查对象e是否为NullPointerException,则必须使用操作符instanceof代替==

if (e instanceof NullPointerException) {
    System.out.println("User cancelled");
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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