Android app with ActionBar NullPointerException with non-standard locale
I've created a pretty basic Android app with an ActionBar and two tabs. It worked fine. Then I added the locale resource directory res/values-de
and inside it strings.xml
with strings translated into German. I changed the language on my Nexus7 to German and the app cannot start after deploying. I have the same problem on the emulator.
Please help me to make this application run in some non-default languages ββon my mobile device? In my case, German ...
An error is reported.
02-07 15:32:41.314: W/dalvikvm(16682): threadid=1: thread exiting with uncaught exception (group=0x40d82930)
02-07 15:32:41.324: E/AndroidRuntime(16682): FATAL EXCEPTION: main
02-07 15:32:41.324: E/AndroidRuntime(16682): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tabactionbar/com.example.tabactionbar.MainActivity}: java.lang.NullPointerException
02-07 15:32:41.324: E/AndroidRuntime(16682): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-07 15:32:41.324: E/AndroidRuntime(16682): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-07 15:32:41.324: E/AndroidRuntime(16682): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-07 15:32:41.324: E/AndroidRuntime(16682): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-07 15:32:41.324: E/AndroidRuntime(16682): at android.os.Handler.dispatchMessage(Handler.java:99)
02-07 15:32:41.324: E/AndroidRuntime(16682): at android.os.Looper.loop(Looper.java:137)
02-07 15:32:41.324: E/AndroidRuntime(16682): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-07 15:32:41.324: E/AndroidRuntime(16682): at java.lang.reflect.Method.invokeNative(Native Method)
02-07 15:32:41.324: E/AndroidRuntime(16682): at java.lang.reflect.Method.invoke(Method.java:511)
02-07 15:32:41.324: E/AndroidRuntime(16682): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-07 15:32:41.324: E/AndroidRuntime(16682): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-07 15:32:41.324: E/AndroidRuntime(16682): at dalvik.system.NativeStart.main(Native Method)
02-07 15:32:41.324: E/AndroidRuntime(16682): **Caused by: java.lang.NullPointerException
02-07 15:32:41.324: E/AndroidRuntime(16682): at com.example.tabactionbar.MainActivity.onCreate(MainActivity.java:20)**
02-07 15:32:41.324: E/AndroidRuntime(16682): at android.app.Activity.performCreate(Activity.java:5104)
02-07 15:32:41.324: E/AndroidRuntime(16682): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-07 15:32:41.324: E/AndroidRuntime(16682): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-07 15:32:41.324: E/AndroidRuntime(16682): ... 11 more
02-07 15:32:41.334: W/ActivityManager(492): Force finishing activity com.example.tabactionbar/.MainActivity
02-07 15:32:41.434: D/dalvikvm(492): GC_FOR_ALLOC freed 546K, 19% free 15994K/19568K, paused 64ms, total 64ms
02-07 15:32:41.574: D/libgps(492): proxy_gps_nmea_cb()
MainActivity code without TabListener:
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
String label1 = getResources().getString(R.string.label1);
Tab tab = actionBar.newTab();
tab.setText(label1);
TabListener<Tab1Fragment> tl = new TabListener<Tab1Fragment>(this,
label1, Tab1Fragment.class);
tab.setTabListener(tl);
actionBar.addTab(tab);
String label2 = getResources().getString(R.string.label2);
tab = actionBar.newTab();
tab.setText(label2);
TabListener<Tab2Fragment> tl2 = new TabListener<Tab2Fragment>(this,
label2, Tab2Fragment.class);
tab.setTabListener(tl2);
actionBar.addTab(tab);
}
Reported line 20 in error actionBar.setNavigationMode (ActionBar.NAVIGATION_MODE_TABS);
strings.xml with German text.
<string name="app_name">TabActionBar</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
<string name="label1">Eins</string>
<string name="label2">Zwei</string>
<string name="body1">Erste</string>
<string name="body2">Zweite</string>
Please help me to make this application run in some non-default languages ββon my mobile device? In my case, German ...
source to share
Check out this discussion: Action Bar - Menu Button - Missing
Anyway, do you also have a styles.xml file inside your values-de folder ? This can cause problems with the ActionBar becoming NULL.
source to share