Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » 实战错误讨论  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 初学者求助,我的第二个程序运行出错。
兔子Roger





发贴: 1
积分: 0
于 2006-09-20 20:14 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
/**
*这个程序主要用来测试类名与文件名的一致性问题
*/
class StudentTest
{
  public static void main(String[] args)
  {
    Student aStudent = new Student();
    aStudent.setName("张楠");
    aStudent.setStudentNum("20030408");
    System.out.println("学生的姓名是:" + aStudent.getName() + ",学号是:" + aStudent.getStudentNum());
  }
}

class People
{

  private String name;
  public String getName()
    {
      return name;
    }
    
  public void setName(String strName)
  {
    name = strName;
  }
}

class Student extends People
{

private String studentNum;
public String getStudentNum()
    {
      return studentNum;
    }
    
public void setStudentNum(String strStudentNum)
    {
      studentNum = strStudentNum;
    }
}

编译没问题,但java StudentTest报错:
Exception in thread "main" java.lang.NoSuchMethodError: main

后来我用教材里的代码编译,运行后报同样的错误。是不是我环境问题啊?但第一个heloworld程序没问题。晕了~~~

谢谢那位帮我看下!先谢了!

classpath: .;E:\Java\jdk1.5.0_08\lib;E:\Java\jdk1.5.0_08\lib\dt.jar;E:\Java\jdk1.5.0_08\lib\tools.jar;E:\Java\jdk1.5.0_08\lib\rt.jar;E:\Java\jdk1.5.0_08\lib\charsets.jar;E:\Java\jdk1.5.0_08\lib\jaws.jar

path:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Symantec\pcAnywhere\;E:\Java\jdk1.5.0_08\bin;C:\Program Files\IDM Computer Solutions\UltraEdit-32



作者 Re:初学者求助,我的第二个程序运行出错。 [Re:兔子Roger]
qingsure





发贴: 3
积分: 0
于 2006-09-20 21:00 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
在我这一切正常,还是经验丰富的前辈出来指教~~


作者 Re:初学者求助,我的第二个程序运行出错。 [Re:兔子Roger]
JiafanZhou



版主


发贴: 736
积分: 61
于 2006-09-21 06:28 user profilesend a private message to usersend email to JiafanZhousearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Your code is 100% right except for the most cases, the class contains the main method will be decalred as a public modifier whereas only one public class is allowed in every file.

Well ,The error is telling you that the error is:

Thrown if an application tries to call a specified method of a class (either static or instance), and that class no longer has a definition of that method.

Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.

Delete the .class files and recompile programs to insure that the .class files are valid.

Kind regards,
Jiafan



When I was a kid I used to pray every night for a new bike. Then I realized that The Lord doesn't work that way, so I stole one and asked him to forgive me.
作者 Re:初学者求助,我的第二个程序运行出错。 [Re:兔子Roger]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2006-09-21 09:20 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
public class StudentTest

... HenryShanley has already provided the details



作者 Re:初学者求助,我的第二个程序运行出错。 [Re:兔子Roger]
ken_chie





发贴: 21
积分: 0
于 2006-09-22 09:40 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Student aStudent = new Student();
我看这个地方好象不对吧
上面的类名是StudentTest
我想是不是应该
StudentTest aStudent = new Student();
这样写就对了啊



作者 Re:初学者求助,我的第二个程序运行出错。 [Re:兔子Roger]
ken_chie





发贴: 21
积分: 0
于 2006-09-22 09:45 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
对不起 我说的有错误
在我这里运行一点问题都没有 直接可以运行出结果来



作者 Re:初学者求助,我的第二个程序运行出错。 [Re:兔子Roger]
zxhzhong





发贴: 1
积分: 0
于 2006-09-25 15:39 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
public class StudentTest


作者 Re:初学者求助,我的第二个程序运行出错。 [Re:兔子Roger]
xudeliang





发贴: 8
积分: 0
于 2006-09-28 10:03 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
环境有问题


作者 Re:初学者求助,我的第二个程序运行出错。 [Re:兔子Roger]
xingchao





发贴: 32
积分: 0
于 2006-10-14 13:41 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
在我这里一切正常阿
可能是你的环境有问题吧。
。。。。。。



作者 Re:初学者求助,我的第二个程序运行出错。 [Re:兔子Roger]
JavaandC





发贴: 230
积分: 15
于 2006-10-17 15:20 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
需要 public 的。

改成public class StudentTest 你这看看可以否?




作者 Re:初学者求助,我的第二个程序运行出错。 [Re:兔子Roger]
snow_lxj





发贴: 7
积分: 0
于 2006-11-12 17:53 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
最好设在path的最前面。我的可以运行阿,该一下环境试试


作者 Re:初学者求助,我的第二个程序运行出错。 [Re:兔子Roger]
bd0571





发贴: 4
积分: 0
于 2006-11-13 12:47 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
如果如楼上的各位所言:运行正常的话。就是path的问题了,把E:\Java\jdk1.5.0_08\bin;放在最前面好了。每次找编译器的时候都是从前往后找的,你前面的那几个路径有可能包含编译器的。你可以查一下你当前的JDK版本,在dos中:java -version;看看是不是你当前所安装的这个,有可能它找到了别的。放在最前面应该可以的。


作者 Re:初学者求助,我的第二个程序运行出错。 [Re:兔子Roger]
lxgsk





发贴: 5
积分: 0
于 2006-11-16 09:48 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
应该就是环境设置的问题



flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   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