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
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 "")
Exception in thread "main" java.lang.NoClassDefFoundError: C:\javatry\ersteanwendung
Caused by: java.lang.ClassNotFoundException: C:\javatry\ersteanwendung
at java.secruity.AccessController.doPrivileged(Native Method)
Could not find the main class: C:\javatry\ersteanwendung. Program will exit.
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
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Joined: May 27, 2010
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.
set a system property
enable verbose output
-version print product version and exit
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
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
load native agent library by full pathname
load Java programming language agent, see java.lang.instrument
show splash screen with specified image
Joined: Apr 10, 2010
You forgot a blank character
Joined: May 27, 2010
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?
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: 123. They might help. Also the "common problems" page in the Java™ Tutorials.
Joined: Oct 13, 2005
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 . . .").