Home | WebServices | Maven | SOA | REST | Agile & SCRUM | Java & JEE
Homepage

Java ResourceBundle - How to avoid java.util.MissingResourceException

This tutorial explains about ResourceBundle, the way a bundle is loaded and hence helps in avoiding java.util.MissingResourceException.

Let us assume your package structure is com.abc and you have placed Thea.properties under this package. Thea.properties just has one line name=karthik. The right way to load this bundle is as in the screen shot below.

loadcorrect (4K)

What will happen if we append properties as in the screen shot below ?

loaderror (4K)

Well, we get java.util.MissingResourceException. Why does it happen? The reason is when we mention getBundle, first a class with the given name and locale [if not specified the default locale is considered] is searched for in the given package [In the above example a class with the name properties is expected under the package com.abc.Thea ]. If a valid Java class is not found then it searches for a file with the extension .properties. So for the MissingResourceException not to occur with the above code, a file with the name properties.properties should be placed under the package com.abc.Thea.properties as in the screen shot below.
proploc (2K)

But this was not our original intention. Hence for the ResourceBundle to be loaded correctly, we should exclude the extension .properties

 

 

Copyrights 2008 Thea Solutions
All rights reserved
Powered by 4creativeweb Solutions