0

In one class I inflate the action bar to find an item and then I return super.oncreatemenuoptions(menu) then in the other class I just use menu.finditem... In the onCreateMenuOptions method without inflating because when I inflated it again two of the items were created. It works fine on Api 15 and 16 but android 4.2.2 throws a null pointer exception whenever I try to use the item in the second class. The phone it crashes on is a Samsung Galaxy s4. Is there any firmware issues with Samsung? Is there anyway around this by checking api in my code? Class 1:

@Override
public boolean onCreateOptionsMenu(Menu menu)
Menuinflater inflater= getMenuInflater();
inflated.inflate (R.menu.actionbar, menu);
MenuItem item= menu.findItem(R.id.search);
return super.onCreateOptionsMenu(menu);

Class 2:

 @Override
public void onCreateOptionsMenu (Menu menu,MenuInflater inflater) {
SearchView SearchView = (SearchView) menu.findItem (R.id.search).getActionView();
}
Taylor Courtney
  • 813
  • 1
  • 6
  • 23

2 Answers2

0

You can get the sdk build version value of device pragmatically within your code by this line. "Integer.valueOf(android.os.Build.VERSION.SDK);" and you can get release build vesion by this line. "String androidOS = Build.VERSION.RELEASE;" But,I didn,t understand why do you need to know the version. I think the problem is with your Sdk.Try to use the updated SDK and Updated IDE.Or try to create a new project and copy all classes in that new project. I hope this will help you.

Zohaib Hassan
  • 984
  • 2
  • 7
  • 11
  • You have to inflate the action bar in each class.Problem is somewhere else.Can You show me your menu file "actionbar.xml"? – Zohaib Hassan May 13 '15 at 11:53
  • Compare your code with the link given below. http://developer.android.com/guide/topics/ui/actionbar.html The proper way to use the Action bar is given in this link.Read this link completely.It will vanish all your confusions about Action Bar. – Zohaib Hassan May 13 '15 at 11:55
  • When I inflate it in both classes two items appear on my kindle device – Taylor Courtney May 13 '15 at 17:56
  • Check your menu_main.xml class in res/menu folder. What you have given the value in app:showAsAction="value"? I think the problem is with your menu file.Re check your menu_main.xml file. – Zohaib Hassan May 17 '15 at 21:20
0

I fixed it by changing the search view android:showAsAction in the menu folder xml from "ifroom" to "always." Also moving the searchView.setOnQueryTextListener(this) from onCreateView to onCreateOptionsMenu but now when I do that it wont work on the older device and vice-versa when I move it back... I think this is a bug with api 19 or newer apis or something.

Taylor Courtney
  • 813
  • 1
  • 6
  • 23