Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当我打开一个活动时,Android应用程序崩溃,但是eclipse没有显示错误_Java_Android_Eclipse - Fatal编程技术网

Java 当我打开一个活动时,Android应用程序崩溃,但是eclipse没有显示错误

Java 当我打开一个活动时,Android应用程序崩溃,但是eclipse没有显示错误,java,android,eclipse,Java,Android,Eclipse,我正在尝试做一个导航抽屉布局。这是我的AddActivity.java: package de.hoffmann.pod2go; import android.app.Activity; import android.content.res.Configuration; import android.os.Bundle; import android.support.v4.app.ActionBarDrawerToggle; import android.support.v4.app.NavU

我正在尝试做一个导航抽屉布局。这是我的AddActivity.java:

package de.hoffmann.pod2go;

import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.NavUtils;
import android.support.v4.widget.DrawerLayout;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

public class AddActivity extends Activity {

    public ActionBarDrawerToggle mDrawerToggle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add);
        // Show the Up button in the action bar.

        DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.left_drawer);
        ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(
                this,                  /* host Activity */
                mDrawerLayout, /* DrawerLayout object */
               R.drawable.ic_drawer,  /* nav drawer icon to replace 'Up' caret */
                R.string.drawer_open,  /* "open drawer" description */
                R.string.drawer_close  /* "close drawer" description */
                ) {

            /** Called when a drawer has settled in a completely closed state. */
            public void onDrawerClosed(View view) {
                getActionBar().setTitle(R.string.title_activity_add);
            }

            /** Called when a drawer has settled in a completely open state. */
            public void onDrawerOpened(View drawerView) {
                getActionBar().setTitle(R.string.drawer_title);
            }
        };


        mDrawerLayout.setDrawerListener(mDrawerToggle);
        getActionBar().setDisplayHomeAsUpEnabled(true); // Pressing the app icon in the action bar will navigate to the parent activity.
        getActionBar().setHomeButtonEnabled(true);

    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
         super.onPostCreate(savedInstanceState);
         // Sync the toggle state after onRestoreInstanceState has occurred.
         mDrawerToggle.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        mDrawerToggle.onConfigurationChanged(newConfig);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
         // Pass the event to ActionBarDrawerToggle, if it returns
         // true, then it has handled the app icon touch event
         if (mDrawerToggle.onOptionsItemSelected(item)) {
             return true;
         }


         switch (item.getItemId()) 
            {
                case android.R.id.home:
                    NavUtils.navigateUpFromSameTask(this);
                    return true;
            }

         return super.onOptionsItemSelected(item);
    }



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.add, menu);
        return true;
    }
}
下面是LogCat在我尝试打开活动时所说的:

java.lang.ClassCastException:android.widget.ListView无法强制转换为android.support.v4.widget.DrawerLayout


我做错了什么?

您确定R.id.left\u抽屉是抽屉布局,而不是列表视图吗?
R.id.left\u抽屉
必须表示列表视图。您是否尝试清理项目并重新运行?Eclipse有时会为所有id创建混乱。ActionBarDrawerToggle的构造函数仅处理抽屉布局,当使用列表视图时,会出现以下错误:构造函数ActionBarDrawerToggle(AddActivity,ListView,int,int,int)未定义。您可以在这里找到my AddActivity.xml:构造函数的第二个参数是指drawer\u布局(外部xml元素)还是left\u drawer(仅用于导航抽屉中的内容的xml元素)?编辑:当我将第二个参数更改为外部元素(drawer\u layout)时,logcatisgivingmeadifferention错误:your layout.xml请@我想我没有layout.xml文件!什么意思?