permaculture playing cards
The moose likes Beginning Java and the fly likes Compiler works, but it doesnt run Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Compiler works, but it doesnt run" Watch "Compiler works, but it doesnt run" New topic

Compiler works, but it doesnt run

Sascha Bever

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 and ersteanwendung.class

The contain of

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.secruity.AccessController.doPrivileged(Native Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
Could not find the main class: C:\javatry\ersteanwendung. Program will exit.

Hope you can help me

Best wishes,
Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
You want to do that:

java -cp c:\javatry\ ersteanwendung

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11881

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
Sascha Bever

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.
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
enable assertions
disable assertions
-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
Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308

You forgot a blank character

Sascha Bever

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

Joined: Oct 13, 2005
Posts: 44545
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

Joined: Oct 13, 2005
Posts: 44545
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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15000

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 8 API documentation
I agree. Here's the link:
subject: Compiler works, but it doesnt run
It's not a secret anymore!