私は、次のエラーが発生して何が起こっているのか認識できません。 私はjavaを初めて使い、javaフレームを使ってフリックフロップゲームを作成しようとしています。助けてください私のコードでNullPointerExceptionと私はそれを取り除く
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:217)
at FlipFlopFrame.setCards(FlipFlopFrame.java:24)
at FlipFlopFrame.<init>(FlipFlopFrame.java:18)
at FlipFlopFrame$1.run(FlipFlopFrame.java:285)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
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.awt.EventQueue.dispatchEvent(EventQueue.java:726)
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)
私のコードは例外ですがここにあります。どのように私はそれを解決し、将来のコードでそのような例外を避けることができますか?おかげ
import javax.swing.ImageIcon;
import javax.swing.JButton;
import logicBehind.logicBehindFlipFlop;
public class FlipFlopFrame extends javax.swing.JFrame {
private boolean wayUp=false;
private ImageIcon im1;
private ImageIcon im2;
private JButton[] pbtn=new JButton[1];
private logicBehindFlipFlop log=new logicBehindFlipFlop();
public FlipFlopFrame() {
initComponents();
setCards();
}
private void setCards()
{
int[] numbers= log.getCardNumbers();
btnC1.setDisabledIcon(new ImageIcon(getClass().getResource("../images/card"+numbers[0]+".png")));
btnC2.setDisabledIcon(new ImageIcon(getClass().getResource("../images/card"+numbers[1]+".png")));
btnC3.setDisabledIcon(new ImageIcon(getClass().getResource("../images/card"+numbers[2]+".png")));
btnC4.setDisabledIcon(new ImageIcon(getClass().getResource("../images/card"+numbers[3]+".png")));
btnC5.setDisabledIcon(new ImageIcon(getClass().getResource("../images/card"+numbers[4]+".png")));
btnC6.setDisabledIcon(new ImageIcon(getClass().getResource("../images/card"+numbers[5]+".png")));
btnC7.setDisabledIcon(new ImageIcon(getClass().getResource("../images/card"+numbers[6]+".png")));
btnC8.setDisabledIcon(new ImageIcon(getClass().getResource("../images/card"+numbers[7]+".png")));
btnC9.setDisabledIcon(new ImageIcon(getClass().getResource("../images/card"+numbers[8]+".png")));
btnC10.setDisabledIcon(new ImageIcon(getClass().getResource("../images/card"+numbers[9]+".png")));
btnC11.setDisabledIcon(new ImageIcon(getClass().getResource("../images/card"+numbers[10]+".png")));
btnC12.setDisabledIcon(new ImageIcon(getClass().getResource("../images/card"+numbers[11]+".png")));
}
private void btnEnabled(JButton btn)
{
if(!wayUp)
{
btn.setEnabled(false);
im1=(ImageIcon) btn.getDisabledIcon();
pbtn[0]=btn;
wayUp=true;
}
else
{
btn.setEnabled(false);
wayUp=false;
}
}
参照このhttp://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it – bramhaag
217が実際として存在する線で参照画像を確認リソース –