• Advertisement
Sign in to follow this  

[java] i can compile JAVA, but cant run CLASSes!

This topic is 4356 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i can compile java files and it generates class files. but i cant run the classes. c:\java_file_location\java HelloWorld ----------- i reinstalled this JRE last night, jre-1_5_0_06-windows-i586-p-iftw. when i try to run i get this error: 'Exception in thread "main" java.lang.NoClassDefFoundError: HelloJava1' ...and yes, this class does exist.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by GekkoCube
c:\java_file_location\java HelloWorld
NoClassDefFoundError: HelloJava1'

A class called "HelloJava1" should be in a file called "HelloJava1.class".
A class called "HelloWorld" should be in a file called "HelloWorld.class".

You have seem to have intermixed class name and file name.

Is your class public? And does it have a public static main method?

Share this post


Link to post
Share on other sites
sorry. the names are all correct.
im using a HelloWorld example that came with a text book on CD.

Share this post


Link to post
Share on other sites
here's a thought...

if i install the java SDK, in my case jdk1.5.0_06, do i need to install the jre (java runtime), which in my case i have jre1.5.0_06 ?

maybe this has somethign to do with it, although i cant see why this is the problem.

Share this post


Link to post
Share on other sites
Can you post the entire code via copy and paste into this forum please?

And does this work:

java -cp . HelloWorld

?

Share this post


Link to post
Share on other sites
Quote:
Original post by GekkoCube
if i install the java SDK, in my case jdk1.5.0_06, do i need to install the jre (java runtime), which in my case i have jre1.5.0_06 ?

The SDK includes the JRE. There should be a JRE folder in the SDK folder.

Of course you cannot run .class files built by Java 1.5 with Java 1.4

Share this post


Link to post
Share on other sites
Fred304

i dont know who you are, but you're a genius.

using java -cp . HelloWorld WORKS!

now allow me to research what the heck this means!

Share this post


Link to post
Share on other sites
okay, i've no idea.

i know the -cp is for classpath.
but i never had to do this before.

and besides, the class exists in the same folder as the call to java.
so what gives?
also, when i exit the java app, the console gets stuck!

Share this post


Link to post
Share on other sites
Check to see if the CLASSPATH environment variable is set. If it is, then that could cause the problem. Don't set the CLASSPATH environment variable globally.

Share this post


Link to post
Share on other sites
the CLASSPATH is set under systems.

but this only has one path, and it's for quicktime.


maybe i SHOULD set the classpath???

Share this post


Link to post
Share on other sites
I finally found the problem!

In my environment variables, my classpath had something on there for quicktime. i deleted that and everything works fine, ie. "c:\java helloworld" rather than "c:\java -cp . helloworld"


here's where i found the helpful post.
http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=2&t=012677

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement