• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NullPointerException - Can't figure this out

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I'm learning J2ME, and am absolutely loving it!!
I ran into a problem with a sample application I'm working on... I cannot seem to get the MIDlet to run. I keep receiving a NullPointerException. This is the code I'm using:

And the error I receive is this:
startApp threw an Exception
java.lang.NullPointerException
java.lang.NullPointerException
at InteractiveGauge.NonInteractiveGauge.startApp(+8)
at javax.microedition.midlet.MIDletProxy.startApp(+7)
at com.sun.midp.midlet.Scheduler.schedule(+225)
at com.sun.midp.dev.DevMIDletSuiteImpl.schedule(+7)
at com.sun.midp.Main.runLocalClass(+20)
at com.sun.midp.Main.main(+68)

Any help would be greatly appreciated... The book's code is IDENTICAL, so I can't figure out what it is that I'm missing...
I'm running it using WTK2.0...

Thanks!
Frank
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Frank:
Please remoive "void" from the statement
public void NonInteractiveGauge()
so that it becomes the constructor for this Midlet class...it is taking it as a method now...
 
Frank Manno
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hemant,
Thank you very much... I knew it had to have been something I overlooked... I can't believe I hadn't noticed that one!
Thanks again!
 
Frank Manno
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alright,
I'm having another problem now... I figured that I'd just continue this thread, rather than starting a new one... My problem is now related to reading image files located on my drive. This is the code I'm running:

The problem is that the IOException is ALWAYS being thrown... And it seems as though it's being thrown here:

the images I have area located in the res/ directory located in the same directory as my MIDlet. I've also tried taking out the first slash so that the path is: "res/ff.png", etc., and it doesn't seem to matter.
Any ideas on this one would be appreciated!
Thanks!
 
author
Posts: 1436
6
Python TypeScript Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The "res/" directory needs to be just under the top level directory of your JAR package.
 
Frank Manno
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Michael Yuan:
The "res/" directory needs to be just under the top level directory of your JAR package.


Hi Michael,
So the resource directory is actually two levels below where the MIDlet is located? Does this also apply when the MIDlet is NOT packaged in a JAR file? I get this error when trying to run it from the SunOne Studio...

Thanks,
Frank
 
Hemant Sareen
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Frank:
You don't have to specify 'res' in the path just use "/image_name"..
Hope it works..
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had the same problem with images when I had a path such as /res/image.png Your SDK should default to the /res directory when looking for image files so you only need to put /image.png as the path, as Hermant stated.
 
Frank Manno
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the tip... I'll keep that in mind! Can the "res" directory not be in the same folder as the MIDlet, or is it just better practice to keep them seperated in their own folders?
Thanks!
 
Greg Schwartz
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The sdk's that I've been using have a directory for each J2ME application. The jar/jad files reside in this main directory. Also in this directory are "class", "rsc" (the equivalent of your "res") and "src" folders. All of my image files are in the "rsc" folder that is within the MIDlets main folder. Hope this helps.

Greg
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic