Archived

This topic is now archived and is closed to further replies.

GekkoCube

application error.

Recommended Posts

I receive an "application error", sometimes a "nullpointerexception error", at various times playing thru my midlet. any ideas what the applic. error could be about? no memory?

Share this post


Link to post
Share on other sites
or you try to access some object you didnt create.
try to monitor your memory by using the two runtime methods (one gets available-memory the other one free-memory - dont know the names at the moment, sorry) and run the garbage collector to get correct results...

greetings and such - atomhamster

Share this post


Link to post
Share on other sites
I ran a test on my S55 and it seems to call the garbage collector by itself very frequently - at least once per second. If the Nokia 7210 emulator is anything like the actual phone, then that phone only runs the GC when it can''t fit an allocation into the remaining memory. (Then it goes and reclaims all it can; and if it still can''t fit in your allocation then you of course crash and burn.)

If you get a message about a NullPointerException - well then, it could hardly be any clearer what''s going on there; the code''s trying to invoke a method on a null reference, or otherwise use null in a way that requires a non-null.

Btw, the methods you''re looking for are Runtime.freeMemory() and Runtime.totalMemory(). These are non-static methods but Runtime is a singleton; so following the usual singleton paradigm of the Java library writers, you have to write something like

long freemem = Runtime.getRuntime().freeMemory();
long totmem = Runtime.getRuntime().totalMemory();

I have the javadoc for MIDP 1.0 downloaded on my HD, but I cannot for the LIFE of me find it on Sun''s website anymore, even though their navigation system seems to exude a certain sense of pride. (it''s not too hard to find the CLDC javadoc though; but that won''t tell you about all the javax.microedition.lcdui stuff...)

Share this post


Link to post
Share on other sites
1) You used a MIDP2.0 function, while your phone supports MIDP1.0.
2) You used a function that your phone doesn''t allow to work. (I hate Nokia)

--
You''re Welcome,
Rick Wong

- sitting in his chair doing the most time-consuming thing..

Share this post


Link to post
Share on other sites
Zahlman: Where did you get those docs?? I have to google everytime I need to know something.

The null pointer exception you get is most likely caused by you not instantiating an object.

ie:

int a[];
a[4] = 1;

or

MyObject a;
a.myMethod ();

Get a trace of your execution and find out what threw the exception. If you can''t trace, make use System.out.println() to track it down.

Regarding your gc woes, make sure you have a wait() in your main loop. If you don''t do this then the GC will be ineffective.

If this doesn''t solve the problem you can manually force the GC to run via System.gc().

Best of luck,
Will

Share this post


Link to post
Share on other sites
quote:
Original post by RPGeezus
Zahlman: Where did you get those docs?? I have to google everytime I need to know something.


I got them off the Sun website... but I CAN''T FIND THEM ANYMORE Just like everyone else, they don''t know how to do good website navigation.

Re wait(), I don''t have one in my main loop but I do have a sleep() which I guess amounts to the same thing... heh :/ I also heard that in some cases using Display.callSerially() can be preferable.

Share this post


Link to post
Share on other sites
Pipo DeClown: Thank you!

Zahlman:
You know, for all the bad ppl say about Microsoft, I must say the have the BEST online documentation. Sun could learn a thing or two from MS''s doc team.

Will

Share this post


Link to post
Share on other sites