当我尝试将图标添加到 Netbeans JFrame 中的按钮时,我遇到了一大堆错误:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:205)
at furnituremanagementsystem.menu.initComponents(menu.java:86)
at furnituremanagementsystem.menu.<init>(menu.java:17)
at furnituremanagementsystem.menu$12.run(menu.java:273)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:727)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.awt.EventQueue$3.run(EventQueue.java:686)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:697)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
问题是它总是在我第二次尝试添加图标时发生。你们能解释一下这个错误是什么意思吗?谢谢你。PS 按钮代码:
jButton5 = new javax.swing.JButton();
jButton5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jButton5.setForeground(new java.awt.Color(255, 0, 0));
jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/furnituremanagementsystem/user-group-icon9878.png"))); // NOI18N
jButton5.setText("Customer");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
jPanel1.add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 170, 230, -1));