[英]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.