We help IT Professionals succeed at work.

java.lang.NoClassDefFoundError: TestZone/java

Chandramouli k
on
checked java -version and javac -version and found no issues. infact i just created Test class and found printing hello successfully.

but not able to execute - java TestZone

Any clues?
import java.util.*; 
import java.util.TimeZone; // this have included after getting error but still no luck :(
public class TestZone { 
    public static void main(String[] args) {
        String[] ids = TimeZone.getAvailableIDs();
	if(args != null)
		System.out.println("notnull"); 

        for(int i = 0; i < ids.length; i++) {
            System.out.println("ID " + i + " " + ids[i]);
        }
    } 
}

Open in new window

Comment
Watch Question

Is the class file created?

Is the class file in the same path as where you are executing the java command?
Chandramouli kArchitect

Author

Commented:
Yes ... i do have source and class files created and stored in the same folder path.

when i say java Test it works fine but java TestZone gives above error.
Chandramouli kArchitect

Author

Commented:
its working fine... i didnt do anything... i havent closed cmd prompt and opened it again... all of a sudden it started priting all zones.

now am more worried...  

am increasing the points if experts help me to understand how did it get fixed and how to reproduce it?

VS
There will be two case when you get that error:
1) before compiling/generating class file, you are trying to run
or
2) you are giving wrong class name while running
Mick BarryJava Developer
Top Expert 2010

Commented:
should be running it with:

java TestZone

not:

java TestZone.java
Chandramouli kArchitect

Author

Commented:
Thanks pramod and Objects. You have helped me to understand something am not aware of...

my comments .

>>before compiling/generating class file, you are trying to run
am using command prompt and notepad (read somewhere this is best way to learn java) so cannot execute before the class file is generated

>>you are giving wrong class name while running
am not typing class name all again i use upperarrow key to get last executed statments - i removed c from javac and .java from class name that's how i have been working for weeks.

>>java TestZone.java
same as above.

is there any other way i could have done something wrong....

it all started when i tried inserting the below lines to check when args could be null and not null (i tried this as part of response i got from an expert to a open question)
if(args != null)
            System.out.println("notnull");

any guess?
Mick BarryJava Developer
Top Expert 2010
Commented:
that error message would only occurr if you had tried to run

java TestZone.java
Chandramouli kArchitect

Author

Commented:
It was still not clear how the issue got resolved?
Chandramouli kArchitect

Author

Commented:
Objects, pramodkrjsr

today have got the same error when tried to answer
http://www.experts-exchange.com/Programming/Languages/Java/New_to_Java/Q_26309116.html

attaching screenshots for your ref.

could you help me understand why am getting this error?
Q-26253048.JPG
Plz share you code in SplitString.java
Chandramouli kArchitect

Author

Commented:
have attached the code.... but am able to execute after *closing* the prompt and open it again... havent done anything with CLASSPATH, have ensured the class files are there and did execute correctly as you see - java SplitString (not SplitString.class)

:(
class SplitString{
	public static void main (String [] args){
	
	//System.out.println("Reader1    "    +reader.readLine());
        //String str[] = reader.readLine().split(",");
	
	String str[] = args[0].split(",");
        int i;
        {
        	int lenght= str.length;
                for(i=0;i<lenght;i++)
                	str[i]= str[i].trim();
                for( i=0;i<lenght;i++)
                	System.out.println(str[i]);
	}


 }
}

Open in new window

Chandramouli kArchitect

Author

Commented:
correction --  java SplitString (not SplitString.class)
read as
java SplitString (not SplitString.java)
plz type below in the prompt and send the output:
echo %classpath%
echo %path%
echo %java_home%
Chandramouli kArchitect

Author

Commented:
>echo %classpath%
%classpath% (is this correct doesnt return anything)

>echo %path%
C:\Program Files\Java\jdk1.5.0_16\bin;C:\oracle\ora92\bin;(and so on...)

>echo %java_home%
C:\Program Files\Java\jdk1.5.0_16

dont think the issue is with classpath or anything... i see a pattern here... had this problem first when i tried to include accessing args and getting the same now. Please refer to last part of my comment ID:32982363