public void myEvent()
{
/*f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);//关闭窗口
}
});
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
System.out.println("退出,按钮干的");
System.exit(0);//终止当前行正在运行的虚拟机
}
});
*/
(问题一:::当我把上面的f和b的监听器注释掉后,他的.class文件能够运行,能够创建出f的窗口和b的按钮。但是当我不对他们的任意一个注释时编译能够通过但是在运行.class文件 是会报D:\JAVA\lianxi\day22>javac AwtDemo.java
D:\JAVA\lianxi\day22>java AwtDemo1
Exception in thread "main" java.lang.NullPointerException
at AwtDemo1.myEvent(AwtDemo.java:56)
at AwtDemo1.init(AwtDemo.java:33)
at AwtDemo1.<init>(AwtDemo.java:22)
at AwtDemo1.main(AwtDemo.java:67)
D:\JAVA\lianxi\day22>
)
(问题二::接着上面的,就是把f和b的监听器注释掉会,他能够创建f的窗口和b的按钮,但是此时但我按下CRTll +c来结束程序时回报下面的错,D:\JAVA\lianxi\day22>javac AwtDemo.java
D:\JAVA\lianxi\day22>java AwtDemo1
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x100a7f17, pid=3928, tid=3628
#
# JRE version: 7.0_05-b05
# Java VM: Java HotSpot(TM) Client VM (23.1-b03 mixed mode, sharing windows-x86
)
# Problematic frame:
# C [GOOGLEPINYIN2.IME+0xa7f17] DllRegisterServer+0x43d47
#
# Failed to write core dump. Minidumps are not enabled by default on client vers
ions of Windows
#
# An error report file with more information is saved as:
# D:\JAVA\lianxi\day22\hs_err_pid3928.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
)
}
} 作者: 杜正华 时间: 2012-10-29 08:50
第一个问题没看出来,第二个问题应该是把public void init()
中的myEvent()注释掉就好了