这是我的代码,现在,它不起作用,当我加载程序时出现此错误
错误
java.net.MalformedURLException at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source) at
java.net.URL.<init>(Unknown Source) at
me.MyTaskbar.com.Image.<init>(Image.java:76) at
me.MyTaskbar.com.MyTaskbar.<init>(MyTaskbar.java:170) at
me.MyTaskbar.com.MyTaskbar$1.run(MyTaskbar.java:48) at
java.awt.event.InvocationEvent.dispatch(Unknown Source) at
java.awt.EventQueue.dispatchEventImpl(Unknown Source) at
java.awt.EventQueue.access$200(Unknown Source) at
java.awt.EventQueue$3.run(Unknown Source) at
java.awt.EventQueue$3.run(Unknown Source) at
java.security.AccessController.doPrivileged(Native Method) at
java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown
Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at
java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(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) Caused by:
java.lang.NullPointerException ... 20 more
代码
//image
URL url;
try {
url = new URL(prop.getProperty("database"));
image1 = new ImageIcon(ImageIO.read(url));
image1 = new ImageIcon(image1.getImage().getScaledInstance(java.awt.Toolkit.getDefaultToolkit().getScreenSize().width, heightLOCATION, BufferedImage.SCALE_SMOOTH));
FaceImage = new JLabel(image1);
FaceImage.setBounds(0,0, java.awt.Toolkit.getDefaultToolkit().getScreenSize().width, heightLOCATION);
window.add(FaceImage);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
private ImageIcon image1;
private JLabel FaceImage;
我正在尝试从名为 config.propeties 的数据库中加载 url,其中包含图像的 url,例如 C://image.jpg 但由于某种原因它不起作用,有人可以帮忙吗?