Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio - Include ResourceBundles in Module

I currently switched from eclipse to android studio. In eclipse I had 2 projects, one android application project and one java project which I included in the android project as library. This java project uses ResourceBundles to create internationalized error messages for it's own errors. This has been my project structure:

/MyApp
   /src
   /res
   ...
/MyLibrary
   /src
   /res (added as source folder to build path)
      /loc
         Bundle_en.properties 

This worked when loading the RessourceBundles as following:

ResourceBundle.getBundle("loc.Bundle", Locale.ENGLISH);

Now I switched to android studio and my new project structure looks like this (added the java library as module):

/MyProject
   /MyApp
      ...
   /MyLibrary
      /src
         /main
            /java
               ...
            /res
               /loc
                  Bundle_en.properties   

But I'm not able to load the ResourceBundles anymore, it's just throwing a java.util.MissingResourceException. I tried a lot of different locations for the ResourceBundles and different paths but I'm going to get crazy because nothing seems to work. Could anybody explain where to put those bundles and how to load them?

Thank you!

like image 953
Horrorente Avatar asked Feb 20 '14 14:02

Horrorente


1 Answers

Faced exactly the same problem. To make it work I finally had to create a resorces folder in my project module's main folder.

Android resources folder

here multiple files starting with the same name (as messages in this picture) gets bundled as a resource bundle.

Finally had to call it using ResourceBundle.getBundle("org.eclipse.paho.client.mqttv3.internal.nls.logcat") or ResourceBundle.getBundle("org.eclipse.paho.client.mqttv3.internal.nls.messages") to get the required resource.

like image 151
Rahul Thakur Avatar answered Oct 03 '22 22:10

Rahul Thakur