Android的工作室 - 包括在模块把ResourceBundle [英] Android Studio - Include ResourceBundles in Module

查看:1146
本文介绍了Android的工作室 - 包括在模块把ResourceBundle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前从日食切换到Android工作室。在Eclipse中我有2项目,一个android应用项目,其中包括我在Android项目作为库中的一个Java项目。这个Java项目采用把ResourceBundle为它创建自己的错误,国际化的错误消息。这一直是我的项目结构:

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的工作室和我的新项目结构看起来像这样(添加了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   

但我不能够再加载把ResourceBundle,它只是抛出一个 java.util.MissingResourceException 。我尝试了很多的把ResourceBundle和不同路径的不同位置,但我会变得疯狂,因为似乎没有任何工作。任何人可以解释在哪里把这些包和如何加载呢?

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 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.

这篇关于Android的工作室 - 包括在模块把ResourceBundle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆