• Post Reply Bookmark Topic Watch Topic
  • New Topic

Package/Access question  RSS feed

 
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.
 
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).
 
author
Sheriff
Posts: 23384
128
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
 
There are 10 kinds of people in this world. Those that understand binary get this tiny ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!