I am having a problem with my image not being displayed on my applet, here is the code, all pertaining to the image;
Image globe;
//Adding Image in init()
Image globe = getImage (getCodeBase (), "C:/Users/Andrew/Downloads/Computer Science/globe.jpg");
//later in code
public void paint (Graphics g)
{
g.drawString ("'The Best Travel Agency in the world' - John Travelta", 400, 675);
g.drawImage(globe, 0, 100, this);
} // paint method
public boolean action (Event e, Object o)
{
if (e.target == DomRep)
{
String DomRepBox = JOptionPane.showInputDialog ("Please Enter your name: ");
}
return true;
}
this is the error I am receiving;
java.lang.NullPointerException
at sun.java2d.pipe.DrawImage.copyImage(Unknown Source)
at sun.java2d.pipe.DrawImage.copyImage(Unknown Source)
at sun.java2d.SunGraphics2D.drawImage(Unknown Source)
at sun.java2d.SunGraphics2D.drawImage(Unknown Source)
at CPT.paint(CPT.java:129)
at sun.awt.RepaintArea.paint(Unknown Source)
at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
C:/Users/Andrew/Downloads/Computer Science/globe.jpg, especially when using applets. Instead, you need to use a relative path based on the relationship between the image and the applet