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

新手求助,编译可以通过,但运行出错
我是新手,向各位大大求助

我的系统Win8.1 64位,安装的1.7.0_45

已经按照的网上的教程设置了path、java_home、classpath等环境变量

前面编写一个类的程序的时候,都可以正确的编译与运行。

但是当程序包括两个类的时候,编译可以通过,但运行出错,提示如下

D:\testjava>javac hello.java

D:\testjava>java hello
Exception in thread "main" java.lang.NoClassDefFoundError: hello (wrong name:
llo)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

D:\testjava>java hello.class
错误: 找不到或无法加载主类 hello.class
------解决方案--------------------
楼主你好:
student.java

   class Student
{
private String name;
private float englishScore;
private float computerScore;
private float historyScore;
private float mathematicsScore;
public void setname(String s)
{
this.name=s;
}
public void setenglishScore(float n)
{
this.englishScore=n;
}
public void setcomputerScore(float n)
{
this.computerScore=n;
}
public void sethistoryScore(float n)
{
this.historyScore=n;
}
public void setmathematicsScore(float n)
{
this.mathematicsScore=n;
}
public String getname()
{
return this.name;
}
public float getenglishScore()
{
return this.englishScore;
}
public float getcomputerScore()
{
return this.computerScore;
}
public float gethistoryScore()
{
return this.historyScore;
}
public float getmathematicsScore()
{
return this.mathematicsScore;
}
public Student(String s)
{
this.setname(s);
}
public float totalScore()
{
float total=this.getenglishScore()+this.getcomputerScore()+this.gethistoryScore()+this.getmathematicsScore();
return total;
}
public float avarageScore()
{
float total=this.getenglishScore()+this.getcomputerScore()+this.gethistoryScore()+this.getmathematicsScore();
float avarage=total/4;
return avarage;
}
public float highScore()
{
float high;
if (this.getenglishScore()>this.getcomputerScore())
{
high=this.getenglishScore();
}else
{
high=this.getcomputerScore();
}
if (high<this.gethistoryScore())
{
high=gethistoryScore();
}
if (high<this.getmathematicsScore())
{
high=getmathematicsScore();
}
return high;
}
public float lowScore()
{
float low;
if (this.getenglishScore()<this.getcomputerScore())
{
low=this.getenglishScore();
}else
{
low=this.getcomputerScore();
}
if (low>this.gethistoryScore())
{
low=gethistoryScore();
}
if (low>this.getmathematicsScore())
{
low=getmathematicsScore();
}
return low;
}
public void PrintStudentInformation()
{
System.out.println("姓名:"+this.getname()+"   英语成绩:"+this.getenglishScore()+"   计算机成绩:"+this.getcomputerScore()+
                 "    历史成绩"+this.gethistoryScore()+"    数学成绩"+this.getmathematicsScore());
System.out.println("总成绩:"+this.totalScore()+"平均成绩:"+this.avarageScore()+"最高分:"+this.highScore()+"最低分:"+this.lowScore());
}

}



2、hello.java

   

public class Hello{
public static void main(String arg[]){
Student student1=null;
student1=new Student("sun");
student1.setenglishScore(90.5f);
student1.setcomputerScore(93.5f);
student1.sethistoryScore(88.0f);
student1.setmathematicsScore(99.0f);
student1.PrintStudentInformation();
}
}



如下:执行

第一步:打开cmd用管理员权限执行哦!

第二步:D:\testjava>javac student.java