Fehlersuche(NullPointerException)

  • Themenstarter Themenstarter Spellsleeper
  • Beginndatum Beginndatum
S

Spellsleeper

Gast
Hi,
ich bin im Moment an einem größerem Projekt, ich bekomme hier eine Exception von der ich nicht ganz verstehe wo sie herkommt:

Code:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at javax.swing.ImageIcon.<init>(Unknown Source)
	at BasicWindow$12.actionPerformed(BasicWindow.java:451)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(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.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$000(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.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.awt.EventQueue$4.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)

Hier die Methode in dem der Fehler auftritt:

Java:
btn1.addActionListener(new ActionListener() {		//ASK-Darstellung
			
			@Override
			public void actionPerformed(ActionEvent e) {
				ImageIcon askOne=new ImageIcon(getClass().getResource("/Transmit/ASK/one.png"));
				ImageIcon askZero=new ImageIcon(getClass().getResource("/Transmit/ASK/zero.png"));
				int x=0;
				for(int i:bitVal){
					if(i==0){
						lblList.get(x).setIcon(askZero);
						x++;
					}else{
						lblList.get(x).setIcon(askOne);
						x++;
					}
				}
			
			}
		});

Hier werden diverse ArrayLists initialisiert:
Java:
.....
static JLabel lblVal1,lblVal2,lblVal3,lblVal4,lblVal5,lblVal6,lblVal7,lblVal8,lbl1,lbl2,lbl3,lbl4,lbl5,lbl6,lbl7,lbl8;
	ArrayList<JLabel> lblList=new ArrayList<JLabel>(Arrays.asList(lbl1,lbl2,lbl3,lbl4,lbl5,lbl6,lbl7,lbl8));
.....
public ArrayList<Integer> bitVal=new ArrayList<Integer>();
.....
txtVal.setText("00000000");
		for(char c:txtVal.getText().toCharArray()){	//bitVal wird vorgefüllt
			bitVal.add((int)c);
		}
......
Falls jemand eine Idee hat ,
ich bin für jede Info dankbar.🙂🙂
 
EVIL

du solltest das laden der bilder an den anfang deines programms *vllt dierekt in die main ?* setzen ... und im EDT dann nur das setzen der bilder ...

warum ?

mit deinem code lädst du jedes mal die bilder neu , packst sie jedesmal in eine neue instanz und weist diese dann irgendwo zu ...

großer designfehler ...
 
Hi,
ich bin im Moment an einem größerem Projekt, ich bekomme hier eine Exception von der ich nicht ganz verstehe wo sie herkommt:

Ich würde mal sagen, dass
Code:
getClass().getResource("/Transmit/ASK/one.png")
oder
Code:
getClass().getResource("/Transmit/ASK/zero.png")
oder auch beide NULL zurück geben.
 

Zurück
Oben