当前位置: 技术问答>java相关
Exception in thread "main" java.lang.NoClassDefFoundError是什么错误?
来源: 互联网 发布时间:2015-04-23
本文导语: 代码如下: import java.awt.*; import java.awt.event.*; import javax.swing.*; class CenteredFrame extends JFrame { public CenteredFrame() { setTitle("CenteredFrame"); addWindowListener(new WindowAdapter() { public void window...
代码如下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class CenteredFrame extends JFrame
{ public CenteredFrame()
{ setTitle("CenteredFrame");
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}
} );
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension d = tk.getScreenSize();
int screenHeight = d.height;
int screenWidth = d.width;
setSize(screenWidth / 2, screenHeight / 2);
setLocation(screenWidth / 4, screenHeight / 4);
Image img = tk.getImage("icon.gif");
setIconImage(img);
}
}
public class CenteredTest
{ public static void main(String[] args)
{ JFrame frame = new CenteredFrame();
frame.show();
}
}
编译过来,但是执行时报错:
C:jdkbin>java CenteredTest
Exception in thread "main" java.lang.NoClassDefFoundError: CenteredTest
请问是何原因引起的?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class CenteredFrame extends JFrame
{ public CenteredFrame()
{ setTitle("CenteredFrame");
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}
} );
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension d = tk.getScreenSize();
int screenHeight = d.height;
int screenWidth = d.width;
setSize(screenWidth / 2, screenHeight / 2);
setLocation(screenWidth / 4, screenHeight / 4);
Image img = tk.getImage("icon.gif");
setIconImage(img);
}
}
public class CenteredTest
{ public static void main(String[] args)
{ JFrame frame = new CenteredFrame();
frame.show();
}
}
编译过来,但是执行时报错:
C:jdkbin>java CenteredTest
Exception in thread "main" java.lang.NoClassDefFoundError: CenteredTest
请问是何原因引起的?
|
你的CLASS文件在哪里?如果就在c:jdkbin下
这样执行c:jdkbin>java -classpath . CenteredTest
如果在其它路径比如d:myjavafile
这样执行c:jdkbin>java -classpath d:myjavafile CenteredTest
这样执行c:jdkbin>java -classpath . CenteredTest
如果在其它路径比如d:myjavafile
这样执行c:jdkbin>java -classpath d:myjavafile CenteredTest
|
看看classpath环境变量中是不是有当前路径? "."
|
o srroy, 没仔细看,,,你有。。
sorry
这个程序在我这里可以运行阿。
是否你的classpath有问题?
sorry
这个程序在我这里可以运行阿。
是否你的classpath有问题?