Java exception | SoloLearn: Learn to code for FREE!

0

Java exception

I Wrote a GUI panel which has got a if sentence: if(A_LIST.isEmpty()) {do something}, but it keeps showing exception in thread "AWT-EventQueue-0" NullPointerException, and I also tried .equals(null) and contains(null), they all shows the exception, anyone can tell me why?? Thanks!

5/21/2020 4:51:05 AM

Maple

3 Answers

New Answer

+2

NullPointerException can be caused if no references exist to an object and thus it was garbage collected by the JVM. For example it can happen if you don't assign your GUI component to a variable. This is just speculation though, it is really hard to guess without actually seeing your code :)

0

Can't remember java graphucs all that well, but in the error stack, check which line it says the error came from, and an NPE means that a null object was passed, no matter what you've done. You should try different cases and check which ones pass a null object and which don't, but note that the error is by your side.

0

Coder's Crux so does that mean no matter what condition l've got, I can't pass in a null element what so ever?