aspose file tools*
The moose likes Beginning Java and the fly likes Package/Access question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Package/Access question" Watch "Package/Access question" New topic
Author

Package/Access question

Krep Lock
Ranch Hand

Joined: Sep 19, 2006
Posts: 43


This compiles and runs fine; both classes belong to the default package because they're in the same file.

If I uncomment the package echo; line, the code compiles fine, but prints the first line then returns a runtime exception of the NoClassDefFoundError variety. I guess I have a dynamic binding problem but I'm not clear enough on access rules to figure why it's happening and especially why it doesn't happen when the classes belong to the "default" package.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
After compilation you get two class files. Both need to be located in the /echo folder (which denotes the package structure).
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19073
    
  40

Krep Lock wrote:
This compiles and runs fine; both classes belong to the default package because they're in the same file.

If I uncomment the package echo; line, the code compiles fine, but prints the first line then returns a runtime exception of the NoClassDefFoundError variety. I guess I have a dynamic binding problem but I'm not clear enough on access rules to figure why it's happening and especially why it doesn't happen when the classes belong to the "default" package.



First, delete all your class files. You probably have a mess of class files -- some probably in a directory named "echo". You need to clean it up.

Second, from your working directory make sure that your java files are in a directory called "echo". Make sure that the Test.java file is in a subdir called echo, which matches the package name.

Compile the Test.java file from the working directory, with..... javac echo\Test.java

Run the Test class from the working directory, with ............... java echo.Test


Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Package/Access question