The Artima Developer Community
Sponsored Link

Java Answers Forum
Strange Situation

5 replies on 1 page. Most recent reply: Sep 3, 2003 8:46 AM by Shant Minassians

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
Ryan

Posts: 7
Nickname: rype69
Registered: Jan, 2003

Strange Situation Posted: Aug 9, 2003 12:55 PM
Reply to this message Reply
Advertisement
Hi all,

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.

Many Thanx,

Ryan Penfold, UK.


Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: Strange Situation Posted: Aug 9, 2003 8:57 PM
Reply to this message Reply
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

java -classpath "%CLASSPATH%;your_classpath_list_goes_here" yourclassname

3. Finally, you may try reinstalling JDK and setting classpath environment variable.

If it doesn't help then you can post your folder settings for your program for us.

Ryan

Posts: 7
Nickname: rype69
Registered: Jan, 2003

Re: Strange Situation Posted: Aug 10, 2003 1:54 AM
Reply to this message Reply
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.

Shant Minassians

Posts: 2
Nickname: shantikx
Registered: Sep, 2003

Re: Strange Situation Posted: Sep 3, 2003 12:35 AM
Reply to this message Reply
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


Why?

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: Strange Situation Posted: Sep 3, 2003 1:02 AM
Reply to this message Reply
package com.syngress;
public class MyClass {


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.

Shant Minassians

Posts: 2
Nickname: shantikx
Registered: Sep, 2003

Re: Strange Situation Posted: Sep 3, 2003 8:46 AM
Reply to this message Reply
Thanks for the recommendation. It did work. I was following the wrong instruction given by the book I am currently reading.

Thanks again.

Flat View: This topic has 5 replies on 1 page
Topic: How to invoke a java program ( service ) which resides at Remote machine? Previous Topic   Next Topic Topic: RUJADEEN - easy FREEWARE Java development tool

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use