• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

package ?

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a class called SecondClass which compiles fine but when I run the class a run time error appears !! why ?
c:\pack\SecondClass.java
c:\pack\SecondClass.class
package pack;
public class SecondClass {
public static void main(String[] args) { System.out.println("Hi"); }
}
I noticed the reson was becuase of the "package pack;" line at the beginning of the programm....Becuase when I comment the line "package pack;", all compiles and runs fine.
But when I leave the line "package pack;" uncommented I get this VERY LONG error line !!!
C:\pack>java SecondClass
Exception in thread "main" java.lang.NoClassDefFoundError: pack (wrong name: test/pack)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
at java.security.SecureClassLoader.defineClass (SecureClassLoader.java:111)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
at sun.misc.Launcher$AppClassLoader.loadClass (Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal (ClassLoader.java:313)
Why is this happening and how do I make things work ? Any feedback !!
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeffry,
Did you set your class path correctly?
NoClassDefFoundError is usually caused by wrogn class path.
when you deal with package, class path is important as you probably know..
Hope this helps.
Sean.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeffry,
To run you class, you run it using one of the following commands:
<pre>C:\>java pack.SecondClass</pre>
or
<pre>C:\pack\>java -classpath ".." pack.SecondClass</pre>
Hope this solves the problem.
Regards,
Beno�t
 
Jeffry Cray
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for solving my problem. I did exactly as you said and it worked!! But beileve it or not, I don't know much about classpath variable. Could you tell me of a web site or a booklette that explaincs exactly what is a "classpath" and a "path" variable and how I can make use of it for java ?
Thanks again

Originally posted by Beno�t d'Oncieu:
Jeffry,
To run you class, you run it using one of the following commands:
<pre>C:\>java pack.SecondClass</pre>
or
<pre>C:\pack\>java -classpath ".." pack.SecondClass</pre>
Hope this solves the problem.
Regards,
Beno�t


 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeffry,
CLASSPATH is one of a number of DOS environment variables. It's normally set in the AUTOEXEC.BAT file which runs whenever you open a DOS-prompt window on Win95.
A 'path' simply refers to the drive and directory on your system where files are found. For example, if you have JDK 1.3 installed on the C: drive in directory JDK1.3 the path would be C:\JDK1.3
The current directory is referenced using a dot (.)
To see how the environment variables on your system are set, type: SET at a DOS prompt ... you should see a list of environment variables. You may or may not see one called CLASSPATH ... depends on your system setup.
If one doesn't exist you can create one by typing something like:
<pre>
set classpath .;c:\myjava
</pre>
It will only be good for the current DOS session (you'd need to reenter it the next time you opened a DOS window).
CNET has a DOS help/how-to tutorial at http://www.help.com/cat/2/191/585/hto/121/1.html?tag=st.hp.cat.bb which should give you more info.
------------------
Jane
The cure for boredom is curiosity.
There is no cure for curiousity.
-- Dorothy Parker
[This message has been edited by Jane Griscti (edited November 01, 2000).]
 
Jeffry Cray
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot Jane !!
Your very nice and I'm really sorry for the late reply... I was SO SO busy lately
Thanx again
[This message has been edited by Jeffry Cray (edited November 04, 2000).]
 
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic