This is my first post in this forum, and I want to ask some question.
I have problems with Java Applet. I am programming Java Applet to acquire data from Laser Range Finder (LRF). The problem is that LRF runs under C language. So I use JNI to call native method. I am succeded in acquiring data from LRF into Java. But having problems when trying to plot the data into applet. The error message says "Exception in thread "AWT-EventQueue-1" java.lang,NullPointerException". Anybody know how to solve this please help me....
Which line is line 58? Is the applet signed, so that native libraries can be loaded?
Ping & DNS - updated with new look and Ping home screen widget
Joined: Jun 13, 2007
Oh, I'm sorry. I should have marks the problem's line number.
Well the line 58 in PlotURGScan.java is:
I'm sorry if I'm wrong, but I guessed the error message is because the array is somehow detected empty or something. But the coordinates printed right before the error occur is from the same array. Therefore I assumes that it is because of the threading in Java Applet (which is still a mystery to me ).
I'm still having the same problem, so do please help me.
arrayResults is null until somebody calls sendArrayResults(), where you use "new" to create an array and assign it to this variable. So if the screen gets painted before sendArrayResults() is called (which will definitely happen) then the line shown will cause a NullPointerException.
Two easy fixes: 1) move the "new int[..." up to the class body, so the member is initialized when the applet is constructed (i.e., so it's never null); or 2) put a condition around the loop where the current error is that says "if (arrayResults != null) ..."
I'm terribly sorry for the late reply. That is because they cut off my internet line.
Thank you for your reply Ernest, but I'm still having problem.
I've tried both solution you told me, but It seems that no matter what I do the arrayResults inside the paint method is always null. why is that?
I've put if(arrayResults != null) and the result is never plotted onto the applet. The same result occur when I move the PlotURGScan am = new PlotURGScan(); into init method.
I'm still new with this applet things and what do paint method actually does still don't quite understand
Joined: Mar 22, 2005
One problem is this section:
which should be
As it is, you're constructing a second PlotURGScan object -which will then receive the result- but you're not using it to paint the data. Instead, you're using the first such object (the applet itself) for painting. Since there seems to be no other reason for having two instances of the object, it can be removed. [ June 25, 2007: Message edited by: Ulf Dittmer ]
Joined: Jun 13, 2007
It's been a while and I haven't properly close this thread. My apologies.
Well the problem is fixed all-right and the solution is in the last post.
Thanks for everybody that has sacrifice their time to post.