【问题标题】:Java Illegal Argument Exception androidJava非法参数异常android
【发布时间】:2014-02-10 13:34:28
【问题描述】:

我遇到这种错误,搜索可能的资源后仍然不起作用。

错误:

java.lang.IllegalArgumentException: View android.widget.ExpandableListView{416b0bc8 VFED.VC. ......ID 0,0-480,0 #7f080005 app:id/lvExp} is not a drawer 

这是我的代码:

ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
private DrawerLayout drawer;
private LinearLayout linear;
Button btn;

HashMap<String, List<String>> listDataChild;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    prepareListData();

    btn = (Button)findViewById(R.id.button1);
    linear = (LinearLayout)findViewById(R.id.linear);
    expListView = (ExpandableListView) findViewById(R.id.lvExp);
    drawer = (DrawerLayout)findViewById(R.id.drawer_layout);

    btn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
        if(!drawer.isDrawerOpen(expListView))
        {
            drawer.openDrawer(expListView);
        }
        else
        {
            drawer.closeDrawer(expListView);
        }

        }
    });

    // get the listview


    // preparing list data


    listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);

    // setting list adapter
    expListView.setAdapter(listAdapter);

对于 XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#f4f4f4" >

<LinearLayout
    android:id="@+id/linear"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="#000000"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >

        <Button
            android:id="@+id/button1"
            android:layout_width="47dp"
            android:layout_height="45dp"
            android:background="@drawable/ic_home" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Drawer"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </LinearLayout>

    <android.support.v4.widget.DrawerLayout

        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!-- The main content view -->
        <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
        <!-- The navigation drawer -->

         <ExpandableListView
            android:id="@+id/lvExp"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:cacheColorHint="#00000000" >
        </ExpandableListView>
    </android.support.v4.widget.DrawerLayout>


  </LinearLayout>

</LinearLayout>

【问题讨论】:

  • 你能发布你的日志猫吗?
  • 由于声誉有限,无法发布 logcat,谢谢

标签: android expandablelistview


【解决方案1】:

if(!drawer.isDrawerOpen(expListView)) expListView 列表不是抽屉时遇到异常。这就是为什么你得到java.lang.IllegalArgumentException:

试试这个post 你会有所了解的。 更多信息link

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-19
    • 2020-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多