I'm incredibly puzzled, I have been coding java for almost 2 years and I have never been as stuck as this.
For some reason, the Java VM will not recognise any classes that aren't in the standard packages - therefore every time I try to execute a class, I get good old "NoClassDefFoundError" and every time I try to compile a class that includes a reference to a class I've written, it says "cannot resolve symbol" even though I have checked that all classes are where they should be. Grrrr! I'm so frustrated - I could crush a grape! What I fail to understand is why this has suddenly started to happen as I've not (knowingly) made any changes to my PC (mind you what with all these resident self-updating programs, anything could have happened).
The other frustration is that I'm at the mercy of Windows XP which for some reason fails to do a system restore to any previous checkpoint.
I'm almost in tears as I have a lot of work to do. If anyone can help me in any way, I'd be grateful to an almost unbelievable extent.
1. Since classes in standard packages are recognized, it seems your JDK installation is ok. 2. You may want to use -classpath option to compile and run your classes so that you don't have to depend on XP classpath settings javac -classpath "%CLASSPATH%;your_classpath_list_goes_here" classfile.java
It works! That means that the classpath variable has been changed for some reason - yet I don't remember doing anything to warrant it's change - never mind. Thanx guys.
I have a question related to the previous issue. However, the solution given did not solve my problem. I was wondering I anyone could give me some help with the following issue.
I have the following directory structure: C:\j2sdk1.4.1_01 C:\Java
Under C:\Java I have: C:\Java\com\syngress\MyClass\
This directory contains the file MyClass.java (so the full path would be C:\Java\com\syngress\MyClass\MyClass.java).
My classpath is set to .;C:\j2sdk1.4.1_01\lib\;C:\Java\
MyClass.java contains the following code: package com.syngress; public class MyClass { public static void main (String [] args) { System.out.println("this is it!"); } }
The only directory from which I can compile this file is C:\Java\com\syngress\MyClass>javac MyClass.java
After compiling with no errors, I try to run this class but no matter where I try to run it from i get the following message: C:\Java\com\syngress\MyClass>java com.syngress.MyClass Exception in thread "main" java.lang.NoClassDefFoundError: com/syngress/MyClass
C:\Java\com\syngress\MyClass>cd\
C:\>java com.syngress.MyClass Exception in thread "main" java.lang.NoClassDefFoundError: com/syngress/MyClass
Why?
Even if I try to import com.syngress.MyClass from a different class such as TheClass.java (in C:\Java\) which contains the following code: import com.syngress.MyClass; class TheClass extends MyClass { public static void main(String args[]) { System.out.println("Hello"); } }
I get the following errors:
C:\Java>javac TheClass.java TheClass.java:1: package com.syngress does not exist import com.syngress.MyClass; ^ TheClass.java:3: cannot resolve symbol symbol : class MyClass location: class TheClass class TheClass extends MyClass { ^ 2 errors
These are first two lines of your program. Those lines imply that your class file (MyClass.class) resides inside com/syngress sub-directory. However from what you have posted that doesn't seems to be the case. You have a folder called MyClass inside com/syngress.
So to sove this you might want to move your MyClass.class file out of MyClass directory and put it under syngress directory. Then compile and run.