由于我发布了对我的应用程序之一的大型更新,我收到了数百份碰撞报告,全部来自不同的摩托罗拉手机。堆栈跟踪没有通过我的应用程序:使用配置时Android上的摩托罗拉特定崩溃
EXCEPTION
java.lang.NullPointerException
at android.content.res.Configuration.updateFrom(Configuration.java:269)
at android.content.res.Resources.updateConfiguration(Resources.java:1257)
at android.app.ActivityThread.handleConfigurationChanged(ActivityThread.java:3701)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1907)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4246)
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:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
at dalvik.system.NativeStart.main(Native Method)
它只发生一次,第一次用户启动应用程序。我认为问题来自下面的这段代码。此代码确保应用程序在启动时始终使用英语,但用户可以选择在SharedPreferences中使用另一种保存在Constant.LOCALE中的语言。程序第一次启动时,会执行“else” - 条款,可能会出现问题。但真的,最奇怪的是,我找不到其他人只有摩托罗拉手机有问题。请注意,它可以在所有其他手机上完美地工作。
public static void setCorrectLanguage(final Context context, final SharedPreferences preferences, final Editor editor) {
final Resources resource = context.getResources();
final Configuration cf = resource.getConfiguration();
final String choosenLanguage = preferences.getString(Constant.LOCALE, null);
final DisplayMetrics dm = resource.getDisplayMetrics();
if(choosenLanguage != null) {
cf.locale = new Locale(choosenLanguage);
resource.updateConfiguration(cf, dm);
} else {
cf.locale = new Locale("en");
resource.updateConfiguration(cf, dm);
editor.putString(Constant.LOCALE, "en");
editor.commit();
}
}
我能看到的唯一的事情就是假设英语语言环境存在。 Android中有没有办法获得当前的语言环境并使用它? – 2010-07-08 15:17:53