On Oct 14, 12:12 pm, Anne Johnson <[email protected]> wrote:
> I am having a strange error message and cannot figure out where the
> problem is:
>
> I have 2 classes located in the directory:\myjavaprograms\foodpackage\
> both classes compile successfully.
>
> When I try to run FoodMain.java - i get the error message below:
>
> C:\myjavaprograms\foodpackage>java FoodMain
> Exception in thread "main" java.lang.NoClassDefFoundError: FoodMain
> Caused by: java.lang.ClassNotFoundException: FoodMain
>         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: FoodMain.  Program will exit.
Looks like runtime cannot find foodMain. Can solve this by running
from parent directory. Like:
c:\myjavaprograms>java foodpackage/FoodMain
>
> C:\myjavaprograms\foodpackage>dir
>  Volume in drive C is HP
>  Volume Serial Number is 5EDE-1E15
>
>  Directory of C:\myjavaprograms\foodpackage
>
> 10/13/2009  11:43 PM    <DIR>          .
> 10/13/2009  11:43 PM    <DIR>          ..
> 10/13/2009  11:50 PM               423 Food.class
> 10/13/2009  11:50 PM               237 Food.java
> 10/13/2009  11:50 PM               743 FoodMain.class
> 10/13/2009  11:48 PM               294 FoodMain.java
>                4 File(s)          1,697 bytes
>                2 Dir(s)  197,894,410,240 bytes free
>
> C:\myjavaprograms\foodpackage>
>
> Food. Java:
> package foodpackage.fruitpackage;
>
> public class Food {
>    private String foodType;
>
> // methods
>
> public void setFoodType(String temp){
> foodType = temp;
>
> }
>
> public String getFoodType(){
>  return foodType;
>
> }
> }
>
> FoodMain:
>
> package foodpackage.fruitpackage;
>
> public class FoodMain{
>
> public static void main(String[] args){
>
> Food apple = new Food();
>
> apple.setFoodType("fruit");
>
> System.out.println(" The food entered is: "+apple.getFoodType());
>
>
>
> }
> }

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to