aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Please Help !!! (package and accessibility) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Please Help !!! (package and accessibility)" Watch "Please Help !!! (package and accessibility)" New topic
Author

Please Help !!! (package and accessibility)

Siu Yong
Greenhorn

Joined: May 31, 2006
Posts: 2
Hi All,

I am new to java. I want to set up different packages such as com.mypackage and com.hispackage so that I can test the access modifiers such as private, protected and default. I have tried a program as follow :

package com.myPackage;

public class MyClass{
public static void main(String [] args){
System.out.println("Hello World");
}
}

I can compile the program but when I run the program I get the following :

C:\MyProgram>java MyClass
Exception in thread "main" java.lang.NoClassDefFoundError: MyClass (wrong name:
com/myPackage/MyClass)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
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)


I think the problem is because the JVM cannot see the class file

Can someone help me to set up the different packages in my win XP environment so that I can test the programs I write in any different folder. My question is how to set up a real developement environment with many different packages.
Firas Zuriekat
Ranch Hand

Joined: May 09, 2006
Posts: 144
create a directory called "com" like this:
c:\myJava>mkdir com

Also, create a subdirectory called "myPackage" like this c:\myJava\com>myPackage

Save the the file in your post (MyClass.java) in myPackage folder.
Then go to the myPackage folder and enter this:

c:\myJava\com\myPackage>javac MyClass.java

You will get compile successful message.

Then to run the class file do the following:
C:\myJava>java com.myPackage.MyClass
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please Help !!! (package and accessibility)