| Author |
Compiler works, but it doesnt run
|
Sascha Bever
Greenhorn
Joined: May 27, 2010
Posts: 3
|
|
Hello at all,
I hope you will understand my english, to apologize previously I am german
Ok, well, I bought the book Head First Java (so it is called or?) and try to type my first program.
After many problems with the compiling and the typing with the whole path to javac instead of just javac or %javac (the problem isnt solve anyway!)
I looked here for my problem, and could fix a bug for the compiler.
But my programme still not run...
OS: Windows 7
Filename "ersteanwendung"
Path to Java "C:\Program Files (x86)\Java\jdk1.6.0_20\bin
Path to the files: "C:\javatry"
So, the compiler create the class file, "javatry" contains now ersteanwendung.java and ersteanwendung.class
The contain of ersteanwendung.java:
Now I try to start the file, and get these error message:
C:\Program Files (x86)\Java\jdk1.6_0_20\bin>java "C:\javatry\ersteanwendung" (Here I have to say that I tried also without "")
The error:
Exception in thread "main" java.lang.NoClassDefFoundError: C:\javatry\ersteanwendung
Caused by: java.lang.ClassNotFoundException: C:\javatry\ersteanwendung
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.secruity.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: C:\javatry\ersteanwendung. Program will exit.
Hope you can help me
Best wishes,
Sascha
|
 |
Nicola Garofalo
Ranch Hand
Joined: Apr 10, 2010
Posts: 308
|
|
You want to do that:
java -cp c:\javatry\ ersteanwendung
|
Bye,
Nicola
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9948
|
|
I believe you have a classpath issue. The simplest thing to do is this:
from your command line of
C:\Program Files (x86)\Java\jdk1.6_0_20\bin>
type this (I think this is right):
java -cp C:\javatry ersteanwendung
Once you've tried that, come back here and let us know what happens
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Sascha Bever
Greenhorn
Joined: May 27, 2010
Posts: 3
|
|
This appears:
C:\Program Files (x86)\Java\jdk1.6.0_20\bin>java -cp C:\javatry\ersteanwendung
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 [deprecated]
The default VM is client.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-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 version search
-? -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. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
|
 |
Nicola Garofalo
Ranch Hand
Joined: Apr 10, 2010
Posts: 308
|
|
You forgot a blank character
|
 |
Sascha Bever
Greenhorn
Joined: May 27, 2010
Posts: 3
|
|
Tought it was a type mistake *grin*.
Well, it works.
I dont know why, but I still accept it.
Thanks a lot
Next problem is, that I always have to type the whole path, instead of java, or javac.
In my system controll, by the point java, is a entry which contain the path to javaw.exe
If I try to add a entry it isnt saved...
What could I do?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32675
|
|
You appear to be adding a classpath, not a path. You need to distinguish the two, which confuse all beginners.
The PATH tells the computer (via the command line/terminal) where to look to find the instruction "java" or "javac" or similar.
The CLASSPATH tells the Java Virtual Machine where to find .class or similar files required for its execution.
Did you set a system environment variable called CLASSPATH (or classpath)? If you did, that is almost always wrong and you should delete it. If some other application set the CLASSPATH, add .; to the beginning of the CLASSPATH (on Windows®; use .: on Unix/Mac/Linux).
Look at these old posts about similar matters: 1 2 3. They might help. Also the "common problems" page in the Java™ Tutorials.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32675
|
|
|
To avoid writing C:\Program Files find the instructions for setting the PATH permanently (§4 in the installation instructions, found from the "common problems" link under "javac is not recognized . . .").
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12921
|
|
Sascha Bever wrote:
Aha, a German "Hello World" program ("I rule! Over the world")
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: Compiler works, but it doesnt run
|
|
|