wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Compiling problems... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Compiling problems..." Watch "Compiling problems..." New topic
Author

Compiling problems...

John Pisci
Ranch Hand

Joined: Dec 19, 2008
Posts: 44
Hi everyone.

I'm having trouble compiling my simple application using the command prompt. Any help would be greatly appreciated!

I keep getting the following error:


Exception in thread "main" java.lang.NoClassDefFoundError: Fruit
Caused by: java.lang.ClassNotFoundException: Fruit
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: Fruit. Program will exit.


This is the application I am trying to compile (incredibly basic!), but want to make sure the compiler works.
Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
there are no problems in your class, how are you compiling the class ?


Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
John Pisci
Ranch Hand

Joined: Dec 19, 2008
Posts: 44
I'm just doing


and then


to run. So really, it compiles fine, but it's the running of the app. that's the problem.
Sorry- should have thought this through before posting!

My CLASSPATH is set to C:\Program Files\Java\jdk1.6.0_11\bin\
My JAVA_HOME is set to C:\Program Files\Java\jdk1.6.0_11

Thanks in advance!
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
I'm not sure if this is the problem (most likely not since I don't know much about java....) but could it be that you have main in an abstract class? I mean I know you can't instantiate an abstract class but would that mean you couldn't use the methods (ie, main) in that abstract class without an instance of as subclass?

Just throwing an idea out there......no idea if it is correct.

EDIT: I just ran the program minus the abstract and it worked. I think not having a public class that isn't abstract is your problem.


SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
John Pisci
Ranch Hand

Joined: Dec 19, 2008
Posts: 44
W. Joe Smith wrote:I'm not sure if this is the problem (most likely not since I don't know much about java....) but could it be that you have main in an abstract class? I mean I know you can't instantiate an abstract class but would that mean you couldn't use the methods (ie, main) in that abstract class without an instance of as subclass?

Just throwing an idea out there......no idea if it is correct.


I was thinking along these lines initially, but it compiles in netbeans so now I've kind of assumed that it's a classpath/java_home issue, just not sure why!?!.

Thanks though!
Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
ok I will make some assumptions:

assume that your class Fruit is in a folder like this one C:/project/food/Fruit.class

now try to do the following:

c:/
cd project
java food.Fruit


because you don't have a class named Fruit you have a class named food.Fruit and you should access it in its fully qualified name.

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18508
    
  40

John Pisci wrote:I'm just doing


and then



You class is in the Food package... so, your class files needs to be in the Food directory. And compiled and ran something like this....

javac Food\Fruit.java

java Food.Fruit


to run. So really, it compiles fine, but it's the running of the app. that's the problem.
Sorry- should have thought this through before posting!

My CLASSPATH is set to C:\Program Files\Java\jdk1.6.0_11\bin\
My JAVA_HOME is set to C:\Program Files\Java\jdk1.6.0_11

Thanks in advance!


The CLASSPATH should be set to where the top of you source is -- in this case, it will need to be set to where the Food directory is (the directory that contains your class files).

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
John Pisci
Ranch Hand

Joined: Dec 19, 2008
Posts: 44
Thanks everyone for your help, but it's sorted now! And it worked with the abstract modifier too.

I changed the CLASSPATH to L:\My Projects\MyJavaApps

I compiled with in the food directory and then ran 'java food.Fruit' from the MyJavaApps folder.

Woohoo!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compiling problems...
 
Similar Threads
Basic Question please answer
Question on how to run an application....
Showing Images in Splash Screen
Question on how to run an application....
Interface - AbstractClass Collision