Android自定义列表幻灯片菜单崩溃

时间:2015-02-12 15:50:01

标签: android crash

我正在为我的项目创建自定义列表幻灯片菜单,在我尝试运行它之后,每次出现此错误都会崩溃。 文件行#1错误膨胀类

file line #1 error inflating class android.support.widget.drawerlayoutt

我的XML:

http://pastebin.com/rx3UShfj

这是我项目的全部代码:

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.DrawerLayout.DrawerListener;
import android.transition.Slide;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SlidingDrawer.OnDrawerCloseListener;
import android.widget.SlidingDrawer.OnDrawerOpenListener;
import android.widget.TextView;
import android.widget.Toast;

    public class MainActivity extends Activity implements OnItemClickListener {

    private DrawerLayout drawerLayout;
    private ListView listView;
    private ActionBarDrawerToggle drawerListener;
    private MyAdapter myAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        drawerLayout = (DrawerLayout) findViewById(R.id.drawerList);
        listView = (ListView) findViewById(R.id.listnewsView);
        myAdapter = new MyAdapter(this);
        listView.setAdapter(myAdapter);
        listView.setOnItemClickListener(this);
        drawerLayout = (DrawerLayout) findViewById(R.id.drawerList);
        drawerListener = new ActionBarDrawerToggle(this, drawerLayout,
                R.drawable.ic_slidelancher, R.string.drawer_open,
                R.string.drawer_close) {
            @Override
            public void onDrawerClosed(View drawerView) {
                // TODO Auto-generated method stub
                Toast.makeText(MainActivity.this, "Slide Menu Closed",
                        Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onDrawerOpened(View drawerView) {
                // TODO Auto-generated method stub
                Toast.makeText(MainActivity.this, "Slide Menu Opened ",
                        Toast.LENGTH_SHORT).show();
            }
        };
        drawerLayout.setDrawerListener(drawerListener);
        getActionBar().setHomeButtonEnabled(true);
        // highlight the home button on the top
        getActionBar().setDisplayHomeAsUpEnabled(true);
        // arrow to go back to home screen

    }

    // pop up the drawer when click on the name on the top (action bar )
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (drawerListener.onOptionsItemSelected(item)) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        // TODO Auto-generated method stub
        super.onConfigurationChanged(newConfig);
        drawerListener.onConfigurationChanged(newConfig);
    }

    // sync the Drawer Layout with What the user see on screen ..
    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onPostCreate(savedInstanceState);
        drawerListener.syncState();
        // Bywdy el 3 icons so3'era lama ts7b el Menu w ykbrha lama trg3ha
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int position,
            long arg3) {
        selectItem(position);
    }

    public void selectItem(int position) {
        listView.setItemChecked(position, true);
    }

    public void setTitle(String title) {
        getActionBar().setTitle(title);
    }

    class MyAdapter extends BaseAdapter {
        private Context context;

        String[] Slidelist;
        int[] images = { R.drawable.ic_calendar, R.drawable.ic_chat,
                R.drawable.ic_cnews, R.drawable.ic_cschdules };

        public MyAdapter(Context context) {
            this.context = context;
            Slidelist = context.getResources().getStringArray(
                    R.array.arrayofNews);

        }

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return Slidelist.length;
        }

        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return Slidelist[position];
        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View row = null;
            if (convertView == null) {
                LayoutInflater inflater = (LayoutInflater) context
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                row = inflater
                        .inflate(R.layout.custom_imageview, parent, false);

            } else {
                row = convertView;

            }
            TextView titleTextView = (TextView) row
                    .findViewById(R.id.textView1);
            ImageView titleImageView = (ImageView) row
                    .findViewById(R.id.imageView1);
            titleTextView.setText(Slidelist[position]);
            titleImageView.setImageResource(images[position]);

            return row;
        }

    }

}

错误日志: http://pastebin.com/fft3Rkes

2 个答案:

答案 0 :(得分:0)

您的XML可能不正确,请确保使用此<android.support.v4.widget.DrawerLayout>

答案 1 :(得分:0)

android.support.widget.drawerlayoutt是输入错误代码的“drawerlayoutt”中的拼写错误还是错误的直接复制粘贴?