标题: 找不到main方法的错误 [打印本页] 作者: 曹文涛 时间: 2011-8-28 16:39 标题: 找不到main方法的错误 求组下面的代码:[code=java]import java.io.File ;
import java.io.OutputStream ;
import java.io.FileOutputStream ;
public class OutputStreamDemo01{
public static void main(String args[]) throws Exception{
File f = new File("e:" + File.separator + "JavaTest" + File.separator + "ch12" + File.separator + "tttttttttt.txt");
OutputStream out = null;
out = new FileOutputStream(f);
String str = "北京欢迎你!!";
byte b[] = str.getBytes();
out.write(b);
out.close();
}
}[/code]运行后报出错误:
Exception in thread "main" java.lang.NoClassDefFoundError: OutputStreamDemo01
Caused by: java.lang.ClassNotFoundException: OutputStreamDemo01
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: OutputStreamDemo01. Program will exit.作者: 黄敏文 时间: 2011-8-28 16:44
你的代码没有问题啊,你有没有编译过啊作者: 匿名 时间: 2011-8-28 16:47 标题: 回复 沙发 的帖子 E:\JavaTest\ch12>javac OutputStreamDemo01.java
E:\JavaTest\ch12>java OutputStreamDemo01
Exception in thread "main" java.lang.NoClassDefFoundError: OutputStreamDemo01
Caused by: java.lang.ClassNotFoundException: OutputStreamDemo01
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: OutputStreamDemo01. Program will exit.