Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

how to compile Packages in java ..?

  Asked By: Pamela    Date: May 16    Category: Java    Views: 1493
  

I have encountered a strange problem

While making package in java ....code as follows

Code:
____________________________________________________________________________
_____
package packageOne;

import java.io.*;

public class mainClass
{
public static void main(String args[])
{
System.out.println("Hello to all");

}
}
____________________________________________________________________________
_____

Above code compiles fines with no error, but when execute it saying "java
mainClass" it gives error.

Exception in thread "main" java.lang.NoClassDefFoundError: mainClass (wrong
name
: packageOne/mainClass)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
3)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Press any key to continue . . .

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Jaime Bowman     Answered On: May 16

this code  is working verry well and no Exception in it
try to recomile and excute it again

 
Didn't find what you were looking for? Find more on how to compile Packages in java ..? Or get search suggestion and latest updates.




Tagged: