ActionBarDrawerToggle中的NullPointerException,导航抽屉,android?

ActionBarDrawerToggle中的NullPointerException,导航抽屉,android?,android,nullpointerexception,navigation-drawer,actionbardrawertoggle,Android,Nullpointerexception,Navigation Drawer,Actionbardrawertoggle,我在ActionBarDrawerToggle中获得NullPointerException 日志: Caused by: java.lang.NullPointerException at com.appp.AppActivity.onPostCreate(AppActivity.java:482) at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1150) at android.ap

我在ActionBarDrawerToggle中获得NullPointerException

日志:

Caused by: java.lang.NullPointerException

at com.appp.AppActivity.onPostCreate(AppActivity.java:482)
at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1150)

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2229)
在onPostCreate中获取错误

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    // Sync the toggle state after onRestoreInstanceState has occurred.
    mDrawerToggle.syncState();
}
通过java代码创建布局

void addSideMenu() {
    mDrawerLayout = new DrawerLayout(this);
    mDrawerLayout.setLayoutParams(new DrawerLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    FrameLayout content_frame = new FrameLayout(this);
    content_frame.setLayoutParams(new DrawerLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    content_layout = new LinearLayout(this);
    content_layout.setOrientation(LinearLayout.VERTICAL);
    content_layout.setLayoutParams(new LinearLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    Toolbar tool = new Toolbar(this);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    tool.setLayoutParams(lp);
    tool.setBackgroundColor(Color.parseColor("#00BBD3"));
    setSupportActionBar(tool);
    TypedValue tv = new TypedValue();
    if (this.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv,
            true)) {
        int actionBarHeight = TypedValue.complexToDimensionPixelSize(
                tv.data, this.getResources().getDisplayMetrics());
        tool.setMinimumHeight(actionBarHeight);
    }

    ListView mDrawerList = new ListView(this);
    mDrawerList.setLayoutParams(new DrawerLayout.LayoutParams(320,
            LayoutParams.MATCH_PARENT, Gravity.START));
    mDrawerList.setBackgroundColor(Color.BLACK);
    content_layout.addView(tool);
    addWebView();

    mDrawerLayout.addView(mDrawerList);
    mDrawerLayout.addView(content_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, tool,
            R.string.action_settings, R.string.action_settings) {

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            invalidateOptionsMenu(); // creates call to
                                        // onPrepareOptionsMenu()
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            invalidateOptionsMenu(); // creates call to
                                        // onPrepareOptionsMenu()
        }
    };
    setContentView(mDrawerLayout);

    mDrawerList.setAdapter(new ArrayAdapter<String>(this,
            R.layout.email_element,
            listArray));


    // Set the drawer toggle as the DrawerListener
    mDrawerLayout.setDrawerListener(mDrawerToggle);
}
void addSideMenu(){
mDrawerLayout=新抽屉布局(此);
mDrawerLayout.setLayoutParams(新的DroperLayout.LayoutParams(
LayoutParams.MATCH_父级,LayoutParams.MATCH_父级);
FrameLayout content\u frame=新的FrameLayout(此);
content\u frame.setLayoutParams(新的DroperLayout.LayoutParams(
LayoutParams.MATCH_父级,LayoutParams.MATCH_父级);
内容\布局=新的线性布局(本);
内容布局。设置方向(线性布局。垂直);
content_layout.setLayoutParams(新的LinearLayout.LayoutParams(
LayoutParams.MATCH_父级,LayoutParams.MATCH_父级);
工具栏工具=新工具栏(此);
LinearLayout.LayoutParams lp=新的LinearLayout.LayoutParams(
LayoutParams.MATCH_父项,LayoutParams.WRAP_内容);
工具设置布局参数(lp);
tool.setBackgroundColor(Color.parseColor(“#00BBD3”);
设置支架操作杆(工具);
TypedValue tv=新的TypedValue();
如果(this.getTheme().resolveAttribute)(android.R.attr.actionBarSize,tv,
正确的){
int actionBarHeight=TypedValue.complexToDimensionPixelSize(
tv.data,this.getResources().getDisplayMetrics());
工具设置最小高度(actionBarHeight);
}
ListView mDrawerList=新建ListView(此);
mDrawerList.setLayoutParams(新抽屉布局)LayoutParams(320,
LayoutParams.MATCH_PARENT,Gravity.START));
mDrawerList.setBackgroundColor(Color.BLACK);
内容\布局。添加视图(工具);
addWebView();
mDrawerLayout.addView(mDrawerList);
mDrawerLayout.addView(内容和布局);
mDrawerToggle=新操作BarDrawerToggle(此,mDrawerLayout,工具,
R.string.action\u设置,R.string.action\u设置){
/**当抽屉处于完全关闭状态时调用*/
公共无效onDrawerClosed(视图){
super.onDrawerClosed(视图);
InvalidateOptions菜单();//创建对的调用
//onPrepareOptions菜单()
}
/**当抽屉处于完全打开状态时调用*/
打开图纸上的公共空白(视图抽屉视图){
super.onDrawerOpened(抽屉视图);
InvalidateOptions菜单();//创建对的调用
//onPrepareOptions菜单()
}
};
setContentView(mDrawerLayout);
mDrawerList.setAdapter(新阵列适配器,
R.layout.email_元素,
列表数组);
//将抽屉开关设置为抽屉定位器
mDrawerLayout.setDrawerListener(mDrawerToggle);
}

我建议删除onpostreate(),并使用下面的代码同步切换,谷歌示例应用程序使用此选项

mDrawerLayout.post(new Runnable() {

            @Override
            public void run() {

                mDrawerToggle.syncState();

            }

        });

mDrawerToggle==null检查它。
它已经不是null了。你能发布更多的代码吗?或者至少是
onCreate
方法,在该方法中初始化
mDrawerToggle
变量?我通过java代码创建布局。更新问题