Could somebody help me please? I've done this
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at Frame.Painter.paint(Main.java:399) at sun.awt.RepaintArea.paintComponent(RepaintArea.java:264) at sun.awt.RepaintArea.paint(RepaintArea.java:240) at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:358) at java.awt.Component.dispatchEventImpl(Component.java:4965) at java.awt.Component.dispatchEvent(Component.java:4711) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) at java.awt.EventQueue$4.run(EventQueue.java:731) at java.awt.EventQueue$4.run(EventQueue.java:729) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:728) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
and code in row 399 is :
class Painter extends Canvas{
Image image;
private URL url;
public void setImage(String file) {
url = null;
try {
url = new File(file).toURI().toURL();
} catch (MalformedURLException ex) {
System.out.println(ex.toString());
}
image = getToolkit().getImage(url);
repaint();
}
public void paint(Graphics g) {
double d = image.getHeight(this) / this.getHeight();
double w = image.getWidth(this) / d;
double x = this.getWidth() / 2 - w / 2;
g.drawImage(image, (int) x, 0, (int) (w), this.getHeight(), this);
}
}
I dont know exactly what's going on there. My program work correctly but I felt disturbing with this error every run. Please tell me what should I do.