テキストフィールドを表示するスイングアプリケーションを実行したいだけです。以下は、生成された例外を実行したときのコードです。
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at textf.<init>(textf.java:10)
at textf$1.run(textf.java:35)
at java.awt.event.InvocationEvent.dispatch(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)
何をすべきか助けてください。
import java.awt.FlowLayout;
import javax.swing.*;
class textf{
JTextField tf;
JFrame j;
textf(){
new JFrame("TextField Demo");
j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
j.setSize(400,200);
j.setLayout(new FlowLayout());
tf=new JTextField("press<Enter>",20);
j.add(tf);
j.setVisible(true);
}
public static void main(String s[]) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new textf();
}
});
}
}