The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
October 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Applet problem

Posted by Jay on October 22, 2001 at 7:34 PM

When I run this code with appletviewer,

import java.awt.*;
import java.net.*;
import java.applet.*;

/**
Trying to display an image in the applet.
*/
public class ImageApplet extends Applet
{
Image pic;

public void init()
{
URL url=null;
try
{
url = new URL("http://www.google.com/images/logo.gif");
pic = getImage(url);
}
catch(Exception e){}
System.out.println(url);
}


public void paint(Graphics g)
{
g.drawImage(pic, 0, 0, this);
}
}

I get the following exception:

Exception occurred during event dispatching:
java.lang.NullPointerException
at sun.awt.windows.WGraphics.drawImage(WGraphics.java:383)
at ImageApplet.paint(ImageApplet.java:26)
at sun.awt.RepaintArea.paint(RepaintArea.java:298)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:196)
at java.awt.Component.dispatchEventImpl(Component.java:2663)
at java.awt.Container.dispatchEventImpl(Container.java:1213)
at java.awt.Component.dispatchEvent(Component.java:2497)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:339)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:131)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:98)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:85)


I think this is some sort of AccessControl Exception. But I do not know how to get around this. Any help is sincerely appreciated.

Thanks,
Jay.


P.S: I am using JDK1.3 on Win2000.






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us