File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compiling problems...

 
John Pisci
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 357
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there are no problems in your class, how are you compiling the class ?
 
John Pisci
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 710
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
John Pisci
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 357
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20828
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
John Pisci
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic