views:

21

answers:

1

Since I published a large update to one of my apps I have received hundreds of crash report, all from different motorola phones. The stack trace does not pass through my app:

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)

It only happens once, the first time the user starts the app. I think the problem comes from this piece of code below. This code does so that the app always uses english when started, but then the user can choose to use another language that is saved at Constant.LOCALE in my SharedPreferences. The first time the program is started, the "else"-clause is executed, it might be there that the problem occurs. But really, the strangest thing is that I cant find other people that have problems with only motorola phones. Do note that it works flawlessly on all other phones.

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();
    }
}
A: 

I encountered a similar problem with Motorola Quench. You can try detecting what locale's are available to you by going into Settings -> Locale and Time -> Try clicking on English or English (Canada) or whatever you're interested in and look through the debug logs (using DDMS) to see the locale returned. Eg. 06-11 02:17:51.831: INFO/BlurServiceMother(129): onConfigurationChanged(): locale changed, logging in to tell server: fr_FR

This will indicate the Locale available to you.

In my case, I was supplying "en" and "fr" as the 2 Locale's but we the Quench doesn't have either available so if it failed to change to one of these then try "en_CA" or "fr_FR" and if it still fails then just return from the method (or display appropriate message) indicating that the language is not supported...

Hope it helps!

jagsaund
I will look into this. However I dont think this is the answer, it is possible to change to a locale that does not exist for an application. I personally has implemented swedish locale for my app, with a "values-se"-folder that is correctly used after I set the locale to "se". Even though the locale is not available under the normal locale-setting in the phone.
sandis