• Post Reply Bookmark Topic Watch Topic
  • New Topic

Annoying MissingResourceBundle Exception  RSS feed

 
Jacky Stark
Ranch Hand
Posts: 45
2
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, need a help....

Can any one provide a sample example of how to use resource bundle to deal with properties file. I have tried everything that is mentioned in OCP guide, resource bundle with properties file and resource bundle with java file both are giving me annoying MissingResourceBundle exception. I have got to know where i am getting wrong...
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 4114
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacky Stark wrote:Hi guys, need a help....

Can any one provide a sample example of how to use resource bundle to deal with properties file. I have tried everything that is mentioned in OCP guide, resource bundle with properties file and resource bundle with java file both are giving me annoying MissingResourceBundle exception. I have got to know where i am getting wrong...

Can you post the code that you are trying to run? If you are running the code exactly as given in the book, may be it is just a minor thing that is causing the issue.
 
Jacky Stark
Ranch Hand
Posts: 45
2
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


When i call getObject it is throwing exception
Help me out at this spot.
 
Paul Clapham
Sheriff
Posts: 22816
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Presumably it's a configuration issue, where your code can't see the resource bundle. You've used "resourceBundle.Zoo" as the base name so you must have a file with that name. Did you put that file in the place where the ResourceBundle expects to find it?
 
Jacky Stark
Ranch Hand
Posts: 45
2
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the contents of the resourcebundle are there in Zoo_en_US class, apart from that do i need to write .properties file too? and main question from where the hell the resourcebundle is fetching for file, i have tried all the locations within my workspace.
 
Paul Clapham
Sheriff
Posts: 22816
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacky Stark wrote:and main question from where the hell the resourcebundle is fetching for file, i have tried all the locations within my workspace.


Yes. Amazingly the API documentation for ResourceBundle doesn't say how it looks for the resource bundle. I suppose it assumes you are able to infer that since it's called a resource bundle, it searches in the same way as the Class.getResource() method searches. That was not at all obvious to me. But if it's true, then first of all you've got the name wrong. It should be "ResourceBundle/Zoo" and that assumes your Zoo class is in the ResourceBundle package.
 
Jacky Stark
Ranch Hand
Posts: 45
2
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tried with that Paul, i am still getting the same exception....
I even tried with Jeanne's solution to include the package info while submitting but still the same exception....
can anyone provide a simple sample regarding this... Out of all topics in OCPJP , only this topic is holding my nerve...
 
Paul Clapham
Sheriff
Posts: 22816
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I looked at my code which uses a ListResourceBundle pretty much like your code. Here's your code:



Here's my code:



Just one question: is there a particular reason why you specified "Locale.US"? My class is just named ca.paulclapham.utility.BNBResource.class and my code works just fine; is your class named resourcebundle.Zoo.class?
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 4114
34
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are making it complicated. Do these simple steps first. It will work:

1. Create a two separate java files in current directory DatesAndLocalization.java and Zoo_en_US.java. Add package resourcebundle; to both of them on top.
2. Compile them using: javac -d . *.java (you will see that a subdirectory named resourcebundle is created and the two class files are placed in it.)
3. Run from current directory using: java -classpath . resourcebundle.DatesAndLocalization

I tested it. It works.

HTH,
Paul.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!