日期:2014-05-20  浏览次数:20764 次

java.lang.ClassNotFoundException异常?
Java code
package cn.com.starit.io;

import java.io.IOException;
import java.io.OutputStream;

public class SystemDemo02 {
    public static void main(String[] args) {
        OutputStream out = System.out;
        try{
            out.write("hello".getBytes());    
        }catch(IOException e){
            e.printStackTrace();
        }
        try{
            out.close();
        }catch(IOException e){
            e.printStackTrace();
        }
    }
}

在myeclipse里输入以上代码报异常:
Java code
java.lang.NoClassDefFoundError: cn/com/starit/io/SystemDemo02
Caused by: java.lang.ClassNotFoundException: cn.com.starit.io.SystemDemo02
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Exception in thread "main" 

但是我把代码拷贝出来,在cmd用javac 、java执行时没有错误!这是为什么啊?

------解决方案--------------------
eclipse编译问题,关闭重启eclipse,然后重新编译。
------解决方案--------------------
ide问题 clean 一下 就可以了
------解决方案--------------------
我放在MyEclipse下面运行没有问题。。。lz
------解决方案--------------------
import java.io.IOException;
import java.io.OutputStream;


public class SystemDemo02 
{
 public static void main(String[] args)
 {
 OutputStream out = System.out;
 try{ out.write("hello".getBytes()); 
}
catch(IOException e)

e.printStackTrace();
 }
 try{ out.close();
 }catch(IOException e)
{
 e.printStackTrace();
 } } }


我用GIV编辑器,在命令窗口运行没有任何的错误和警告呀!!!
输出是:hello
------解决方案--------------------
程序木有问题
重启一下机子试试
------解决方案--------------------
感觉是找不到类,是不是没有编译,试试手动编译.
------解决方案--------------------
是不是改过类名?
或者移动过包,而eclipse没重新编译。
去看下编译后的.class文件在哪里。
------解决方案--------------------
不是代码的问题,看看有没有重新编译,找找编译后的class是不是以前的!