我有一个使用导航抽屉的应用程序,可以在手机上正常使用。但它不适用于模拟器。如果我点击导航抽屉上的任何项目。模拟器只是挂起。
这是我在Logcat中获得的:
08-01 00:11:08.342: W/ActionBarDrawerToggleHoneycomb(2745): Couldn't set home-as-up indicator via JB-MR2 API
08-01 00:11:08.342: W/ActionBarDrawerToggleHoneycomb(2745): java.lang.NullPointerException: expected receiver of type android.app.ActionBar, but got null
08-01 00:11:08.342: W/ActionBarDrawerToggleHoneycomb(2745): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 00:11:08.342: W/ActionBarDrawerToggleHoneycomb(2745): at java.lang.reflect.Method.invoke(Method.java:515)
08-01 00:11:08.342: W/ActionBarDrawerToggleHoneycomb(2745): at android.support.v4.app.ActionBarDrawerToggleHoneycomb.setActionBarUpIndicator(ActionBarDrawerToggleHoneycomb.java:55)
08-01 00:11:08.342: W/ActionBarDrawerToggleHoneycomb(2745): at android.support.v4.app.ActionBarDrawerToggle$ActionBarDrawerToggleImplHC.setActionBarUpIndicator(ActionBarDrawerToggle.java:130)
08-01 00:11:08.342: W/ActionBarDrawerToggleHoneycomb(2745): at android.support.v4.app.ActionBarDrawerToggle.setActionBarUpIndicator(ActionBarDrawerToggle.java:372)
08-01 00:11:08.342: W/ActionBarDrawerToggleHoneycomb(2745): at android.support.v4.app.ActionBarDrawerToggle.syncState(ActionBarDrawerToggle.java:230)
08-01 00:11:08.342: W/ActionBarDrawerToggleHoneycomb(2745): at com.places.logic.NavDrawerActivity.onPostCreate(NavDrawerActivity.java:199)
08-01 00:11:08.342: W/ActionBarDrawerToggleHoneycomb(2745): at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1150)
显示NullPointerException
的行是
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
我的mDrawwerToggle初始化代码:
mDrawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description for accessibility */
R.string.drawer_close /* "close drawer" description for accessibility */
) {
public void onDrawerClosed(View view) {
// getActionBar().setTitle(mTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
public void onDrawerOpened(View drawerView) {
// getActionBar().setTitle(mDrawerTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
答案 0 :(得分:0)
删除object(Illuminate\Support\ViewErrorBag)#652 (1) { ["bags":protected]=> array(0) { } }
,然后尝试此
onPostCreateMethod()