0
votes
try{
        imgball = Image.createImage("/ball.jpg");
        //imgpad = Image.createImage("/ball.jpg");
    }
    catch(Exception e)
    {}

The above code works as it is. But when i open imgpad statement, it gives me error of uncaught NullPointerException ? What can be wrong ?

P.S. I am working in a different Thread. If that matters.

3

3 Answers

0
votes

The NullPointerException (NPE) must be later in your code. Your catch block will catch any NPE during image load.

0
votes

As mdma mentioned, the NullPointerException must be later because when the Image.createImage("/ball.jpg"); fails, it will throw an Exception that you catch. Since you catch it and then do nothing, the value of imgball will be unset (null).

Since you are working from a different Thread, it's possible that you are accessing the variable too soon, but I assume the above reason is more accurate because imgball will probably always fail to be created since you give it the absolute path.

0
votes

Ok. It was my mistake. I'd like to make it clear here for others to know.

The mistake I made was actually from the main thread. I'd written following :

        refcan = new ReflectCanvas(2); 
        d.setCurrent(refcan);

And I was loading images in the constructor ReflectCanvas(). So it could bear the speed upto one image but not for two :)