Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Wierd AWT exception on loading graphics



On Sunday, Jul 6, 2003, at 18:24 America/New_York, David Leader wrote:
I've been sort of on holiday working on a small awt app (MetaFlux) under OS 9 (ide CodeWarrior 8) on my iBook reusing well-established code to load a background graphic. The app was fine until suddenly it started throwing the following run-time exception:

Exception Occurred:
java.lang.NullPointerException
at sun.misc.Cache.get(Cache.java)
at sun.awt.SunToolkit.getImageFromHash(SunToolkit.java)
at sun.awt.SunToolkit.getImage(SunToolkit.java)
...
at java.lang.Thread.run(Thread.java)

Toolkit.getImage() is wonky. It has to cache, because that's how Sun implemented it originally (for some reason), and now people are absolutely dependent on it. You should really use Toolkit.createImage() instead, as it doesn't cache. Yes, requires you to write some code. On the other hand, you will have control over what that code does, managing your resources.

It's easy for me to imagine that the setup of the cache in question could be easily screwed up by running code in a secondary thread before anything else in AWT was touched. Like I said, there is just sooooo much magic going on in AWT you have no control of ...

If you want to make the least number of changes in your code, I think I would try changing the way you are running your Runnable (via Thread.start(), presumably), to use EventQueue.invokeAndWait() or invokeLater() as appropriate. That way, the code will run on a Thread which AWT controls a bit more, and, in fact, >should< add a little more latency to the system, which will also help ensure the stuff needed to be set up, is actually set up.

email@hidden
Patrick Mueller
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.

References: 
 >Wierd AWT exception on loading graphics (From: David Leader <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.