这是我的代码:
public class className extends Activity{
private MenuActivity menuActivity;
@Override
public void onCreate(Bundle savedInstanceState) {
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class
.getDeclaredField("sHasPermanentMenuKey");
if (menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception e) {
e.printStackTrace();
}
menuActivity = new MenuActivity(this, context, R.menu.menu);
);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menuActivity.onCreateOptionsMenu(menu); // <--
return super.onCreateOptionsMenu(menu);
}
}
public class MenuActivity {
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = mRootActivity.getMenuInflater();
inflater.inflate(typeMenu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
}
// ...
}
我收到一个NullPointerException
连续的:
menuActivity.onCreateOptionsMenu(menu);
这个例外只存在于一些像 Galaxy Note 这样的手机上。你知道为什么会有这个例外吗?