• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

main() & package question

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All-

Working my way through S&B and ran into a behavior I don't understand.

Here's the code:


This code compiles fine. When trying to run the code, however, I get a runtime exception as follows:


My question is this: If I remove the package statements from this file and the associated Zoo.java file, the code runs fine. With the package statements, I get the runtime error above.

I can't find an explanation of this behavior anywhere. Can someone enlighten me?

Thanks,

MArk
 
Mark Supinski
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I found my own solution.

package classes must be in a directory with a name corresponding to the package declaration. Moving the files into a foobar directory eliminated the runtime exception.

Note, however that java must be invoked from the root level. Thus, if one runs java Moo from within the foobar directory, the runtime exception occurs. If one steps back to the parent directory and runs java foobar/Moo it works properly.

Mark
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

java foobar/Moo it works properly.


I'm assuming you meant java foobar.Moo
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic