Hello Mihai, Thanks a lot for replying to the post.
I finally worked around it. There was no problem in the class and the way it was implemented. Everything was clearly instantiated and referenced. The main culprit was how I was compiling it. I was able to compile the Food class, but not FoodMain class as it was looking for Food class. I was able to compile and generate the .class file, by compiling both the files together bu using "javac *.java". But again after compiling I was having trouble running the .class file - its gave ClassDefNotFoundError, which I guess was because of the classpath problem. As I was compiling it from the subdirectory where it resided.I managed to run it flawlessly by going to the root folder (Linux) and then running with the classpath option, as here : "java - classpath <folder-where-package-is-present> <package-structure>". Thanks again for replying to my post, and I gave the explanation so as it can help other people having such problem. With regards Amit. On Mar 23, 12:39 am, Mihai DINCA <mihai.di...@free.fr> wrote: > Hi Amit, > > There must be some mismatch in the way the class Food.java is used > inside FoodMain and where the files are physically located. Can you send > the code of FoodMain and explain in which directory are located the files? > > I mean, in the DOS window in which you type "javac FoodMain.java", what > is the current directory and in which sub-directory are located your > .java files? > > Hope it helps > Mihai > > Le 22/03/2011 16:47, Amit a crit : > > > > > > > > > I dont understnad what the problem is. > > > In order to check my logic, I recreated the same scenario in Netbeans > > and it works perfectly. Can anyone please suggest something? > > > I finally managed to compile my FoodMain.java by compiling both the > > files simulataniously with "javac *.java", but when I try and run > > FoodMain - its gives me "NoClassDefFoundError". What do you think the > > problem is? > > > Thanks. > > > On Mar 22, 5:27 pm, Amit<amitah...@gmail.com> wrote: > >> Hello, > > >> I am doing the following homework exercises which asks us to create > >> two .java files in package foodpackage.fruitpackage. The files are > >> Food.java and FoodMain.java. > > >> I created and complied Food.java and when I am doing the same for > >> FoodMain.java and try to access Food class from it says symbol not > >> found. > > >> I am pretty sure that I have done everything correctly. And in any > >> case they are in the same package, so Food class should be available > >> to FoodMain class. Both the files are in fruitpackage directory, then > >> why doesnt it work? Can anyone help me on it? > > >> Thanks > > >> With regards. -- To post to this group, send email to javaprogrammingwithpassion@googlegroups.com To unsubscribe from this group, send email to javaprogrammingwithpassion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en