Need some help about Java

Asked By 10 points N/A Posted on -

I make a simulation using IDE NETBEANS but there is a warning: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
on source code :


Anybody know how to finish it?

Best Answer by Allen Kenneth
Answered By 0 points N/A #94482

Need some help about Java


Null Pointer Exception is normally thrown when a NULL value is somehow assigned. For example, there may be no RouterA to add. This is a simple thing, wherever you get such problem, you need to use null OBJECTS INSTEAD OF ONLY null. The another wayout is to check using a if-else construct for NULL values. This helps in overcoming the error. 

You may submit the rest of the code for us to debug. Only two lines of code is not enough to identify the problem. So, please try out the above and if not overcome, post the entire code. 


Best Answer
Best Answer
Answered By 20 points N/A #94483

Need some help about Java



Hello Milodiaz,
I suggest you post the full error message (Null pointer exception) here. That is much concerned when resolving the problem. 
'Null pointer exception' is by far a most common error which can be seen in Java. They are exceptions thrown out when you attempt to use a reference that directs to no location existing in the memory. 
And also the debugging of null pointer exceptions is very simple most of the times.
Identify the line where it occurs, check if there are any null references there. You may add 'if', 'else' statements to do that. Once you identify the specific reference with the exception, it will be simple to fix the code. 
In this case, there seems to be an issue with the "routerA". Check where routerA is declared and initiated, check its value changes. Like i said, its difficult to state the location of the bug because you haven't posted the full error message. But i do hope you will get some idea about which i have been talking about. 
Good luck with debugging! 
Tip: Do not use try catch scopes to catch the exception, its not entirely practical.


Login/Register to Answer

Related Questions