求助:运行java程序出现问题
几经周折,编译好程序生成.class文件,用java 执行时无出现预期显示,而出现以下文字,求解。C:\Users\Jacob>java -classpath e:\program\OurFirstProgram
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [depre
The default VM is client.
-cp <class search path of directories and zip/jar file
-classpath <class search path of directories and zip/j
A ; separated list of directories, JAR a
and ZIP archives to search for class fil
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g
see also, -agentlib:jdwp=help and -age
-agentpath:<pathname>[=<options>]
load native agent library by full pathna
-javaagent:<jarpath>[=<options>]
load Java programming language agent, se
-splash:<imagepath>
show splash screen with specified image
搜索更多相关的解决方案:
java
----------------解决方案--------------------------------------------------------
先看看环境变量有没有问题,然后就是。。。好像命令不是那样执行的吧:
。。。。。。java E:\My //运行E下的My.class,具体的楼主自己改下
----------------解决方案--------------------------------------------------------
是命令行不正确
----------------解决方案--------------------------------------------------------
回复 2楼 qq1023569223
不行,按2楼的输入:java e:\program\OurFirstProgram 后就出现如下提示。C:\Users\Jacob>java e:\program\OurFirstProgram
Exception in thread "main" java.lang.NoClassDefFoundError: e:\program\OurFirstPr
ogram
Caused by: java.lang.ClassNotFoundException: e:\program\OurFirstProgram
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)
Could not find the main class: e:\program\OurFirstProgram. Program will exit.
按教材的解释好像是找不到类,但我在执行前明明用javac编译了并生成了.class文件,为何还执行不了。。。。。。
我的jdk安装在c盘,在执行前,我运行了此参数:path c:\program files\java\jdk1.6\bin
以下是我按教材里的源码,请各位指教一下我哪里出错了。
public class OurFirstProgram
{
public static void main(String[] args)
{
System.out.println("Kratatoa EAST of Java??");
}
}
按书上的例子练习编写了几个程序,结果都和上面一样.
编写后.java和.class文件都齐全,用cmd运行java。
[ 本帖最后由 cocopig 于 2011-1-9 23:31 编辑 ]
----------------解决方案--------------------------------------------------------
原来要先进入保存.CLASS的文件夹在运行。。。。。。。搞了一大堆终于有反应了。
----------------解决方案--------------------------------------------------------