if( currentTimeslot.isEmpty()){
System.out.println("Do stuff");
}
为什么会出现NullPointerException
?如何检查字符串是否为NULL
并在其为NULL
时执行操作?每当currentTimeslot
等于NULL
时,就会出现该错误。以下是控制台消息:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at PM.ui.MainFrame.getJPanelTopMenu(MainFrame.java:382)
NullPointerException
的catch块可能会隐藏原始错误,导致以后出现其他更微妙的问题。请参阅PMD上的Strict Exceptions和HP Fortify分类法:软件安全错误上的差劣的错误处理:程序捕获NullPointerException。 - Paul Vargas