• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Exception in thread "AWT-EventQueue-1"

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Which line is line 58? Is the applet signed, so that native libraries can be loaded?
 
Aji Prasetyo
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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) ..."
 
Aji Prasetyo
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic