Also wo und wie du Methoden schreibst solltest du schon wissen. Sollte es außerdem auch eine Methode sein? Du hast nämlich eine Variable die genau so heißt.
habs auch gemerkt.
Code:
hilfe.add(new AbstractAction("Spielregeln") {
public void actionPerformed(ActionEvent e){
File spregeln = new File("spielregeln.txt");
try {
new FileReader(spregeln);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("Spielregeln...");
JDialog d = new JDialog();
JTextArea ta = new JTextArea();
ta.setEditable(false);
ta.setLineWrap(true);
ta.setBackground(Color.black);
ta.setWrapStyleWord(true);
try {
ta.read(null, spregeln);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ta.setForeground(Color.white);
d.add(ta);
d.setTitle(".:Hangman:. - Spielregeln");
d.setSize( 300, 450 );
d.setResizable(false);
d.setLocation (450, 0);
d.setVisible( true );
}
Also wenn ich jetzt das programm starte und auf den menüpunkt spielregeln gehe kommen in der console folgende fehlermeldungen:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.text.DefaultEditorKit.read(Unknown Source)
at javax.swing.text.JTextComponent.read(Unknown Source)
at Hangman$3.actionPerformed(Hangman.java:295)
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.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.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.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)
da blick ich jetzt garnicht mehr durch