public static void main (String args[ ]){}的声明是为了运行console程序的,如果你的class不需要接收从console输入的参数,那么可以不定义这个函数。 看你的帖子,应该是javac没有出错,但是java运行出错。 你的完全的程序是你帖出来的这个吗?有没有加了什么package的定义?
你编译的class没有在你编译的目录下被执行,原因大概是: Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found. The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.
c:\j2sdk1.4.1_02\binclasspath=c:\j2sdk1.4.1_02\lib\tools.jar
文件名和主类名一致,大小写敏感
1.你保存的文件名是否和你的类名一致.大小写敏感
2.你如何运行的,是在dos下吗?,如果是,先用javac和java命令试一下,看你的设置是否正确
3.至于public 说来话长,:)你找相关的书看,
javac c:\HelloWorldApp.java
java c:\HelloWorldApp出错。
进到你保存文件的目录在用javac是一下,如果不出错
可以在此目录下javac HelloWorldApp.java
有qq吗? 我的50696908
看你的帖子,应该是javac没有出错,但是java运行出错。
你的完全的程序是你帖出来的这个吗?有没有加了什么package的定义?
classpath=c:\j2sdk1.4.1_02\lib\tools.jar
把生成的HelloWorldApp.class文件拷贝到比如D:\java\test\中,然后在classpath环境变量中添加D:\java\test路径。之后,重新起一个dos窗口,然后随便在哪个路径下面敲:java HelloWorldApp,都会有结果的
运行还是在dos下进入bin用java HelloWorldApp;
哈哈,我要下线了,
你没有试??
Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found. The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.
没有规定一定要在编译目录下执行class的,那岂不太傻了。
最主要的是把相关目录加在classpath里面
程序
public class HelloWorldApp {
public static void main (String args[]){ //[]这里不要有空格
System.out.println("Hello World!");
}
}编译
javac -classpath . HelloWorldApp.java
运行
java -classpath . HelloWorldApp
如果不行,把“.”改成绝对路径。一定没问题!
再:
c:\javac HelloWorldApp.java
c:\java HelloWorldApp
试试吧
我试过了,dojsp月下秋风的方法行得通!
此外,我还修改了环境变量classpath=....+";c:"后
把HelloWorldApp.java拷到c:\
再:
c:\javac HelloWorldApp.java
c:\java HelloWorldApp
也行得通
slowlywerot你觉得呢
不过正主儿溜了,我想874