• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Compiler works, but it doesnt run

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You want to do that:

java -cp c:\javatry\ ersteanwendung



 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sascha Bever
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You forgot a blank character

 
Sascha Bever
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Marshal
Posts: 79943
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 79943
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 . . .").
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sascha Bever wrote:


Aha, a German "Hello World" program ("I rule! Over the world")
 
Where all the women are strong, all the men are good looking and all the tiny ads are above average:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic