# exception in thread awt-eventqueue-0 java.lang.nullpointerexception



## lukas1799 (15. Aug 2014)

Hallo habe heute ein Programm zur Notenbilanz erstellt welches aus einen Programmierbuch stammt.
Habe es so wie es im Buch steht gemacht doch trotzdem kommt immer derselbe Fehler und ich komme nicht weiter.
Bitte um eure Hilfe!!!


```
package gui11;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JOptionPane;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JLabel;

public class Notenbilanz extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	public int notenzahl,i;
	public double [] noten;
	public double summe,besteNote,schlechtesteNote,durchschnitt;
	private JLabel lblDurchschnitt;
	private JLabel lblAnzahl;
	private JLabel lblBesteNote;
	private JLabel lblSchlechtesteNote;
	private JLabel lblNote;
	private JLabel lblNewLabel;
	private JButton btnbernehmen;
	private JButton btnbernehmenNoten;
	private JButton btnNeueBerechnung;
	private JButton btnEnde;
	private JLabel lblNoten;
	
	

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Notenbilanz frame = new Notenbilanz();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Notenbilanz() {
		setTitle("Notenbilanz");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 346, 333);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		textField = new JTextField();
		textField.setBounds(22, 33, 32, 20);
		contentPane.add(textField);
		textField.setColumns(10);
		
		
		
		
		
		
		
		
		btnEnde = new JButton("Ende");
		btnEnde.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		btnEnde.setBounds(219, 249, 89, 23);
		contentPane.add(btnEnde);
		
		
		
		textField_1 = new JTextField();
		textField_1.setVisible(false);
		textField_1.setBounds(22, 90, 32, 20);
		contentPane.add(textField_1);
		textField_1.setColumns(10);
		
		lblNewLabel = new JLabel("Anzahl der Noten");
		lblNewLabel.setBounds(22, 11, 128, 14);
		contentPane.add(lblNewLabel);
		
		lblAnzahl = new JLabel("");
		lblAnzahl.setBounds(22, 132, 196, 14);
		contentPane.add(lblAnzahl);
		
		lblBesteNote = new JLabel("");
		lblBesteNote.setBounds(22, 157, 196, 14);
		contentPane.add(lblBesteNote);
		
		lblSchlechtesteNote = new JLabel("");
		lblSchlechtesteNote.setBounds(22, 182, 196, 14);
		contentPane.add(lblSchlechtesteNote);
		
		lblDurchschnitt = new JLabel("");
		lblDurchschnitt.setBounds(22, 207, 196, 14);
		contentPane.add(lblDurchschnitt);
		
		lblNote = new JLabel("1.Note");
		lblNote.setVisible(false);
		lblNote.setBounds(22, 64, 83, 14);
		contentPane.add(lblNote);
		
		lblNoten = new JLabel("");
		lblNoten.setBounds(22, 228, 263, 14);
		contentPane.add(lblNoten);
		
		
		btnbernehmen = new JButton("\u00DCbernehmen");
		btnbernehmen.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(! textField.getText().equals("")){
					notenzahl = Integer.parseInt(textField.getText());
					summe = 0;
					i= 1;
					besteNote = 6;
					schlechtesteNote=0;
					btnbernehmen.setVisible(false);
					textField.setEditable(false);
					textField_1.setVisible(true);
					textField_1.setEditable(true);
					btnbernehmenNoten.setVisible(true);
					textField_1.requestFocus();
					lblNote.setVisible(true);
					
					
				}
				else{
					JOptionPane.showMessageDialog(null, "Geben Sie die Anzahl der Noten ein!");
					textField.requestFocus();
				}
			}
		});
		
		btnbernehmenNoten = new JButton("\u00DCbernehmen");
		btnbernehmenNoten.setVisible(false);

		btnbernehmenNoten.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {

				if(! textField_1.getText().equals("")&& Double.parseDouble(textField_1.getText())<=6 && Double.parseDouble(textField_1.getText())>=1){
					
					summe = summe + Double.parseDouble(textField_1.getText());
					noten [i - 1]= Double.parseDouble(textField_1.getText());
					
					
					durchschnitt = summe/i;
					lblDurchschnitt.setText("Notendurchschnitt: " + durchschnitt);
					lblAnzahl.setText("Anzahl der Noten: "+ Integer.toString(i));
					if(Double.parseDouble(textField_1.getText())> schlechtesteNote){
						schlechtesteNote = Double.parseDouble(textField_1.getText());
						lblSchlechtesteNote.setText("Schlechteste Note: " + Double.toString(schlechtesteNote));
					}
					if(Double.parseDouble(textField_1.getText())<= besteNote){
						besteNote = Double.parseDouble(textField_1.getText());
						lblBesteNote.setText("Beste Note: " + Double.toString(besteNote));
					}
					if (i == notenzahl){
						durchschnitt = summe/notenzahl;
						btnbernehmenNoten.setVisible(false);
						textField_1.setEditable(false);
						btnNeueBerechnung.setVisible(true);
						for(int i=0;i<noten.length;i++){
							lblNoten.setText("Noten: " + noten[i]);
						}
						
					}
					else{
						i++;
						lblNote.setText(i +".Note");
						textField_1.setText("");
						textField_1.requestFocus();
						
					}
					
					
			
				}
				else{
					JOptionPane.showMessageDialog(null, "Gültige Note eingeben!");
					textField_1.requestFocus();
					}
				
			}
		});
		btnbernehmenNoten.setBounds(102, 76, 119, 23);
		contentPane.add(btnbernehmenNoten);
		btnbernehmen.setBounds(112, 32, 119, 23);
		contentPane.add(btnbernehmen);
		
		btnNeueBerechnung = new JButton("Neue Berechnung");
		btnNeueBerechnung.setVisible(false);
		btnNeueBerechnung.setBounds(149, 33, 136, 22);
		contentPane.add(btnNeueBerechnung);
		
		
		
		
		
		btnNeueBerechnung.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				i=1;
				lblNote.setText(Integer.toString(i)+ ".Note");
				summe =0;
				besteNote = 6;
				schlechtesteNote = 0;
				btnbernehmen.setVisible(true);
				textField.setEditable(true);
				lblNote.setVisible(false);
				textField_1.setVisible(false);
				textField_1.setText("");
				btnbernehmenNoten.setVisible(false);
				textField.setText("");
				textField.requestFocus();
				lblBesteNote.setText("");
				lblSchlechtesteNote.setText("");
				lblAnzahl.setText("");
				lblDurchschnitt.setText("");
				btnNeueBerechnung.setVisible(false);
				
				
				
			}
		});
		
	}
}
```


Und hier die Fehlermeldung:

xception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at gui11.Notenbilanz$4.actionPerformed(Notenbilanz.java:164)
	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.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$400(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)


----------



## Flown (16. Aug 2014)

Dein noten Array ist nicht initialisiert und somit null;

Du holst dir zwar die Anzahl der Noten aber dir fehlt noch sowas wie:


```
noten = new double[notenzahl];
```


----------



## lukas1799 (16. Aug 2014)

Vielen Dank!!! Das war das Problem.
Manchmal hat man einfach ein Brett vor dem Kopf


----------

