• Post Reply Bookmark Topic Watch Topic
  • New Topic

Package/Access question

 
Krep Lock
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22635
111
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!