Exception in thread "main" java.lang.NullPointerException at sun.applet.AppletAudioClip.<init>(AppletAudioClip.java:65) at java.applet.Applet.newAudioClip(Applet.java:313) at GUI_Basic.Exercise16_20.<init>(Exercise16_20.java:23) at GUI_Basic.Exercise16_20.main(Exercise16_20.java:12)
空指针:JFrame frame = new Exercise16_20();貌似是jframe没有引用到吧。检查下
没有啊 我在其他编译器和敲javac都可以编译
URL u = getClass().getResource("src/GUI_Basic/aaaa.wav"); 这句话有问题,,,,,我修改了一下就好了public Exercise16_20() {
File file =new File("src/GUI_Basic/aaaa.wav"); URL u = null; try { u = file.toURL(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } AudioClip a = Applet.newAudioClip(u); a.loop();
Exception in thread "main" java.lang.NullPointerException
at sun.applet.AppletAudioClip.<init>(AppletAudioClip.java:65)
at java.applet.Applet.newAudioClip(Applet.java:313)
at GUI_Basic.Exercise16_20.<init>(Exercise16_20.java:23)
at GUI_Basic.Exercise16_20.main(Exercise16_20.java:12)
这句话有问题,,,,,我修改了一下就好了public Exercise16_20() {
File file =new File("src/GUI_Basic/aaaa.wav");
URL u = null;
try {
u = file.toURL();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
AudioClip a = Applet.newAudioClip(u);
a.loop();
add(new DrawRec());
}
如果你在其他环境下应该是能找到那个文件,但是你在eclipse下找不到了,所以