Вопрос

I've run into sort of a strange problem. I'm working on an application targetAPI = 11. I'm using theActionbar.TabListener to implement two tabs and everything works great. However I now created a new "values-de" folder for German strings to use for German devices. Now, when I set my device to German and want to launch the application, it immediately crashes having a nullpointer in:

  final ActionBar actionBar = getActionBar();
  actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

Why does it only occur with the device set to German (I assume it has something to do with my values-de, I just copied the entire "values" folder, renaming the copy to "values-de")

And how can I fix this without huge design workarounds? It works perfectly for the English language but I'd like to add multi-language support.

Thanks.

EDIT 1 - Stacktrace: (sorry forgot)

03-18 01:56:02.575: E/AndroidRuntime(23037): FATAL EXCEPTION: main
03-18 01:56:02.575: E/AndroidRuntime(23037): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.motioncoding.mobilesms/com.motioncoding.mobilesms.core.LaunchActivity}: java.lang.NullPointerException
03-18 01:56:02.575: E/AndroidRuntime(23037):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-18 01:56:02.575: E/AndroidRuntime(23037):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-18 01:56:02.575: E/AndroidRuntime(23037):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-18 01:56:02.575: E/AndroidRuntime(23037):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-18 01:56:02.575: E/AndroidRuntime(23037):    at android.os.Handler.dispatchMessage(Handler.java:99)
03-18 01:56:02.575: E/AndroidRuntime(23037):    at android.os.Looper.loop(Looper.java:137)
03-18 01:56:02.575: E/AndroidRuntime(23037):    at android.app.ActivityThread.main(ActivityThread.java:5041)
03-18 01:56:02.575: E/AndroidRuntime(23037):    at java.lang.reflect.Method.invokeNative(Native Method)
03-18 01:56:02.575: E/AndroidRuntime(23037):    at java.lang.reflect.Method.invoke(Method.java:511)
03-18 01:56:02.575: E/AndroidRuntime(23037):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-18 01:56:02.575: E/AndroidRuntime(23037):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-18 01:56:02.575: E/AndroidRuntime(23037):    at dalvik.system.NativeStart.main(Native Method)
03-18 01:56:02.575: E/AndroidRuntime(23037): Caused by: java.lang.NullPointerException
03-18 01:56:02.575: E/AndroidRuntime(23037):    at com.motioncoding.mobilesms.core.LaunchActivity.onCreate(LaunchActivity.java:43)
03-18 01:56:02.575: E/AndroidRuntime(23037):    at android.app.Activity.performCreate(Activity.java:5104)
03-18 01:56:02.575: E/AndroidRuntime(23037):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-18 01:56:02.575: E/AndroidRuntime(23037):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-18 01:56:02.575: E/AndroidRuntime(23037):    ... 11 more
Это было полезно?

Решение

Problem with copying over styles.xml from values to values-<lang> is that it is not allowed and confuses Android since it is a duplicate. However allowed resources in values-<lang> are strings.xml and arrays.xml as these resources are the only ones that are subject to become translated.

However it is possible to have styles.xml, dimens.xml and colors.xml in values-<lang> folders when they are targeted specific versions of the API. So they would have to be in i.e. values-de-v11.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top