Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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: 23586
138
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!