aspose file tools*
The moose likes Applets and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Exception in thread "AWT-EventQueue-1"" Watch "Exception in thread "AWT-EventQueue-1"" New topic
Author

Exception in thread "AWT-EventQueue-1"

Aji Prasetyo
Ranch Hand

Joined: Jun 13, 2007
Posts: 65
Hello...

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....

This is my source-code


This is my native-code:


This is my output:


Thank you very much....
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
Welcome to JavaRanch.

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
Aji Prasetyo
Ranch Hand

Joined: Jun 13, 2007
Posts: 65
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.

Thank you.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

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) ..."


[Jess in Action][AskingGoodQuestions]
Aji Prasetyo
Ranch Hand

Joined: Jun 13, 2007
Posts: 65
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

Please help.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
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 ]
Aji Prasetyo
Ranch Hand

Joined: Jun 13, 2007
Posts: 65
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.

Good luck for you guys.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception in thread "AWT-EventQueue-1"
 
Similar Threads
CHEECKY but i need help FAST please!
GZIP deflating response from server failure help!
Character Frequency Counter in C(?)
A simple syntax question, pls help
100 times "hello world" without loop or recursive