本文介绍了Android Studio - 在模块中包含 ResourceBundles的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前从 eclipse 切换到 android studio.在 eclipse 中,我有 2 个项目,一个 android 应用程序项目和一个 java 项目,我将它们作为库包含在 android 项目中.这个 java 项目使用 ResourceBundles 为它自己的错误创建国际化的错误消息.这是我的项目结构:

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

这在加载 RessourceBundles 时起作用,如下所示:

This worked when loading the RessourceBundles as following:

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

现在我切换到android studio,我的新项目结构看起来像这样(添加了java库作为模块):

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

但我无法再加载 ResourceBundles,它只是抛出一个 java.util.MissingResourceException.我为 ResourceBundles 尝试了很多不同的位置和不同的路径,但我会发疯,因为似乎没有任何效果.有人能解释一下把这些包放在哪里以及如何加载它们吗?

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?

谢谢!

推荐答案

面临完全相同的问题.为了让它工作,我最终不得不在我的项目模块的主文件夹中创建一个 resorces 文件夹.

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

此处以相同名称开头的多个文件(如本图中的消息)被捆绑为一个资源包.

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

最后不得不使用ResourceBundle.getBundle("org.eclipse.paho.client.mqttv3.internal.nls.logcat")或者ResourceBundle.getBundle("org.eclipse.paho.client.mqttv3.internal.nls.messages")获取所需资源.

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

这篇关于Android Studio - 在模块中包含 ResourceBundles的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 07:36