Exception in thread "main" java.lang.NoClassDefNotFoundError: Main/class
Could you explain me the problem and could you tell me how to solve it?
Thank you!
/RAM/
leave out .class, just use "java Main"
More information here:
http://java.sun.com/docs/books/tutorial/getStarted/problems/index.html
Uzytkownik "Derek Tandy" <kra...@gmail.com> napisal w wiadomosci
news:1167249057.4...@48g2000cwx.googlegroups.com...
Please help...
Uzytkownik "Thomas Kellerer" <TAAXAD...@spammotel.com> napisal w
wiadomosci news:4vg1arF...@mid.individual.net...
package helloworld;
public class Main {
public Main() {
}
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
Użytkownik "R.A.M." <r_ahi...@poczta.onet.pl> napisał w wiadomości
news:emuig9$fhr$1...@news.onet.pl...
Scott
On Dec 27, 12:25 pm, "R.A.M." <r_ahims...@poczta.onet.pl> wrote:
> Here source code:
>
> package helloworld;
> public class Main {
> public Main() {
> }
> public static void main(String[] args) {
> System.out.println("Hello, world!");
> }
>
> }U¿ytkownik "R.A.M." <r_ahims...@poczta.onet.pl> napisa³ w wiadomo¶cinews:emuig9$fhr$1...@news.onet.pl...
See the second line where it says "wrong name helloworld/Main"?
That's because you've got a package name and you're not using it to
invoke the class. You need to include the package name as part of
the class name with a dot separator (after copying the file to the
correct location.)
Example:
1. Source and compiled class are currently in
c:\JavaProjects\MainSample
2. Create a directory under MainSample named helloworld. Package
names require the compiled class to be in a named subdirectory.
3. Copy Main.class to helloworld.
4. From the source directory type:
java -classpath c:\JavaProjects\MainSample helloworld.Main
Note that helloworld.Main is not just Main. It can be considered
like a "virtual class name". It includes the package. That's how
the JVM knows which class you want to run (you could have Main
classes in other packages.)
The -classpath argument tells the compiler the ROOT to the top
level directory of the package. So *after* the classpath arg you
must provide the the class name, but since you have a package in
the name it has to include that too. The oddity is that you don't
give the JVM helloworld/Main, you give it helloworld.Main. The JVM
figures out that the dot separator indicates a backslash or slash.
There is a lot more to know about classpaths too. You can get into
a lot of trouble by ignoring classpath issues. Once you start
using jar files it changes things, so don't rush past learning
about packages and classpath now.