I have just moved from Eclipse to Android Studio, and I am using the Appcompat library because it comes by default in Android Studio and it is hard to deactivate it.
The problem is that when I create a ActiveBar, the items that should be shown in the Overflow menu, never appear, neither the overflow menu icon (3 dots).
Only the items in the bar are created, and if I touch the hardware key for opening the overflow menu, the app crushes.
MainActivity.java:
public class MainActivity extends ActionBarActivity {
public final static String EXTRA_MESSAGE = "com.learning.app1.MESSAGE";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
}
main_activity_actions:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_search"
android:title="@string/action_search"
android:icon="@drawable/ic_action_search"
app:showAsAction="ifRoom" />
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
app:showAsAction="never"/>
Logcat:
01-24 02:48:18.111 14717-14717/com.learning.myapplication W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x412fa438)
01-24 02:48:18.131 14717-14717/com.learning.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at com.android.internal.policy.impl.PhoneWindow.onKeyUpPanel(PhoneWindow.java:986)
at com.android.internal.policy.impl.PhoneWindow.onKeyUp(PhoneWindow.java:1687)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2098)
at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3621)
at android.view.ViewRootImpl.handleImeFinishedEvent(ViewRootImpl.java:3591)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:2834)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4905)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
I used the Blank Activity that comes with Android Studio, and only modified the main_activity_actions XML file. I don't know if did I something wrong or if the Appcompat library has a bug.
Please if you could help me I would be gratefull. Thank you.
It is a common issue on LG devices. Look at link in my comment.