• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help me !

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why doesn't this program run ?
I've set the classpath=c:\;.;
package com.deepak.jav;
public class Test {
public static void main(String[] args) {
System.out.println("why isn't this program working");
}
}
It compiles, but doesnt not run with :
c:\com\deepak\jav\java Test
Could someone tell me why it gives me classnotfound error ?
Thanx
Deepak
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. c:\com\deepak\jav\java Test would try to run a java interpreter in the c:\com\deepak\jav directory. Do you have one there?
2. Is there a Test.class file in the place you think it is? Is it actually in c:\com\deepak\jav?
3. Since your classpath only mentions \ and . as directories where classes would be found, I don't know if it will find c:\com\deepak\jav\Test.class. I could be wrong on this point, though.
Gauth
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gauthaman Ravindran:
1. c:\com\deepak\jav\java Test would try to run a java interpreter in the c:\com\deepak\jav directory. Do you have one there?
2. Is there a Test.class file in the place you think it is? Is it actually in c:\com\deepak\jav?
3. Since your classpath only mentions \ and . as directories where classes would be found, I don't know if it will find c:\com\deepak\jav\Test.class. I could be wrong on this point, though.
Gauth


Your real close, since he has . in his classpath, the file could reside in a directory com\deepak\jav below the Current Directory he is in ie if he is in c:\test then the file could be in c:\test\com\deepak\jav. Additionally since he has c:\ in his classpath com could start at the root. Java searches each path in the class path and then from that point the directory structure that matches The package. To execute this program lets say it's in c:\com\deepak\jav
from the root
java com.deepak.jav.Test

 
Deepak M
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gauthaman Ravindran:
1. c:\com\deepak\jav\java Test would try to run a java interpreter in the c:\com\deepak\jav directory. Do you have one there?
I've set the PATH variable to c:\jdk1.2.2\bin
2. Is there a Test.class file in the place you think it is? Is it actually in c:\com\deepak\jav?
It is actually in c:\com\deepak\jav - isn't that the right place for it to be ?

3. Since your classpath only mentions \ and . as directories where classes would be found, I don't know if it will find c:\com\deepak\jav\Test.class. I could be wrong on this point, though.
I appened C:\com\deepak\jav to the classpath as well, it continues to give me java.lang.NoClassDefFoundError
Gauth


 
Gauthaman Ravindran
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens when you change directory to c:\com\deepak\jav and type java Test?
Gauth
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gauthaman Ravindran:
What happens when you change directory to c:\com\deepak\jav and type java Test?
Gauth


To execute a class you need the fully qualified name. When you type java Test, it is looking for Test with no package declaration in the current working directory. What it finds is Test.class that belongs to com.deepak.jav so, isn't the currect one and you get a classnotfound error.
A fully qualified name is the package followed by the class name
ie com.deepak.jav.Test!
 
Deepak M
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gauthaman Ravindran:
What happens when you change directory to c:\com\deepak\jav and type java Test?
Gauth


classpath is set to c:\;.;
This is what happens when I execute java Test from c:\com\deepak\jav
C:\com\deepak\jav>java Test
Exception in thread "main" java.lang.NoClassDefFoundError: Test (wrong name: com/deepak/jav/Test)
however when I say java com.deepak.jav.Test from C:\ it works !
Thanx for yr help Carl !

[This message has been edited by Deepak M (edited July 15, 2000).]
 
Gauthaman Ravindran
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


To execute a class you need the fully qualified name. When you type java Test, it is looking for Test with no package declaration in the current working directory. What it finds is Test.class that belongs to com.deepak.jav so, isn't the currect one and you get a classnotfound error.
A fully qualified name is the package followed by the class name
ie com.deepak.jav.Test!


Ah. I understand too, now. Thanks.
Gauth
reply
    Bookmark Topic Watch Topic
  • New Topic