getString()崩溃已发布的应用程序

时间:2012-09-11 05:09:04

标签: android xml localization crash

我有一些带有字符串的本地化文件,例如

values
values-ru
values-es
etc.

在每个文件夹中都有一个strings.xml文件,其中包含相同的键但值不同。

在调试模式下,它完美运行。但是当我从Play Market下载应用程序时,它会在每个区域设置上与Resources$NotFoundException崩溃。

另外,我做了

Locale locale = getBaseContext().getResources().getConfiguration().locale; 
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        getBaseContext().getResources().updateConfiguration(config,                                 getBaseContext().getResources().getDisplayMetrics());
初始化期间

。可能是原因吗?

有什么建议吗?

从dev登录。控制台:

android.content.res.Resources$NotFoundException: String resource ID #0x7f080010
at android.content.res.Resources.getText(Resources.java:201)
at android.content.res.Resources.getString(Resources.java:254)
at android.content.Context.getString(Context.java:182)
at com.companyName.appName.menuActivity.onWindowFocusChanged(menuActivity.java:115)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:1986)
at android.view.View.dispatchWindowFocusChanged(View.java:3788)
at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:658)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1921)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

我删除了这部分

Locale locale = getBaseContext().getResources().getConfiguration().locale; 
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        getBaseContext().getResources().updateConfiguration(config,                                 getBaseContext().getResources().getDisplayMetrics());

它有效。正如我所建议的,没有必要修复语言环境,系统将使用所需的资源。

相关问题