Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

who execute without using package ?

Status
Not open for further replies.

haux

Programmer
Apr 11, 2001
79
DZ
Hello ;)

i have already used JBuilder (to compile and excute my progs), and all time
i create a new package so all classes have this in top :

package MyPackage;

but when i excecute it with consol mode (without JBuilder4) i have this exception :

#java MyProg
Exception in thread "main java.lang.NoClassDefFoundError : MyProg (wrong name:
myprog/MyProg)
.................(and other error messages)

Can somebody tell me what i have missed

thanks for all.
 
How are you executing it?

When you place a class in a package, you can no longer invoke it using

java <classname>

instead, you have to use

java <packagename>.<classname>

So, for instance here is a simple class:

<begin Helloworld.java>

package helloworld;

public class Hellowrld {
public static void main (String args []) {
System.out.println(&quot;Helloworld!&quot;);
}
}
<end Helloworld.java>

Now, after compiling, I will either have to have the directory helloworld in my classpath or I will have to be in the parent directory of the helloworld directory and I would type the following to run this program:

java helloworld.Hellworld

Hope this helps,

Charles
 
I had just do what you said.............EUREKA!.
Thank you very very very much for your help ;)
 
Glad to help. Good thing you saw through all the typos in my post.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top