Hello guys,
I am pretty new at (good) programming, so I had some pretty bad code I was using until I
ran across some code and decided to model my code after it.
I have the code so it has no errors, but when I run it (NetBeans) it doesn't show up, and
gives me this very long error:
run:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1045)
at java.awt.Container.add(Container.java:927)
at jPad.jpad.<init>(jpad.java:18)
at jPad.jpad.createAndShowGUI(jpad.java:29)
at jPad.jpad.access$000(jpad.java:12)
at jPad.jpad$1.run(jpad.java:41)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
BUILD SUCCESSFUL (total time: 1 second)
Here is the file I am trying to run:
// Re-writing the start.java file
package jPad;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* @author JimmyD
*/
public class jpad extends JPanel implements ActionListener {
JTextArea mainTextArea;
public jpad() {
super(new BorderLayout());
add(mainTextArea, BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent e) {
mainTextArea.append(" Once! ");
}
private static void createAndShowGUI() {
JFrame mainWin = new JFrame("JPad v0.1");
mainWin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JComponent newContentPane = new jpad();
newContentPane.setOpaque(true);
mainWin.setContentPane(newContentPane);
mainWin.setSize(400, 600);
mainWin.setLocation(100, 100);
mainWin.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
Where is the error coming from? And it could be a simple thing I messed up, since I
don't completely understand how all of the code in this file works.
- WolfShield