Topic: 编译通过了,但无法运行,java.lang.NoClassDefFoundError,求助

  Print this page

1.编译通过了,但无法运行,java.lang.NoClassDefFoundError,求助 Copy to clipboard
Posted by: like_angel
Posted on: 2005-10-08 14:20

class Lesson22
{
  public static void main(String args[])
  {
    int x;
    try
    {
    x =System.in.read();
   }catch(Exception e){}
    while(x !='q')
    {
      System.out.println((char)x);
      try
      {
     x =System.in.read();
  }catch(Exception e){}
  }
  }
}
运行后出现错误:
Exception in thread "main" java.lang.NoClassDefFoundError: lesson22 (wrong name:
Lesson22)
谢谢大家帮忙了

2.Re:帮我解决一下问题谢谢了(variable x might not have been initialized) [Re: like_angel] Copy to clipboard
Posted by: why
Posted on: 2005-10-08 19:59

> variable x might not have been initialized
Then initialize x, i.e.
int x = 0;

> 运行后出现错误
That is compiling, not 运行.Smile

3.Re:编译通过了,但无法运行,java.lang.NoClassDefFoundError,求助 [Re: like_angel] Copy to clipboard
Posted by: like_angel
Posted on: 2005-10-09 10:41

谢谢,我马上重新发

4.Re:编译通过了,但无法运行,java.lang.NoClassDefFoundError,求助 [Re: like_angel] Copy to clipboard
Posted by: why
Posted on: 2005-10-09 12:19

NoClassDefFoundError: lesson22

do a search with keyword NoClassDefFoundError
http://www.cjsdn.net/post/search

name your java file Lesson22.java, it has to match the class name.

5.Re:编译通过了,但无法运行,java.lang.NoClassDefFoundError,求助 [Re: like_angel] Copy to clipboard
Posted by: tqm
Posted on: 2005-10-09 13:38

把x定义为类变量就ok了

6.Re:编译通过了,但无法运行,java.lang.NoClassDefFoundError,求助 [Re: like_angel] Copy to clipboard
Posted by: waitray
Posted on: 2005-10-13 00:02

是不是你的classpath没设置好?
我copy你的程序,除了X要初始化以外,在Eclipse下运行得了哦...而且文件名可以任意取
在命令行 G:\JAVA>java Lesson22下面也可以运行呀

我想会不会是你的classpath没设置好?


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923