2014-02-06 108 views
0

我遇到這種錯誤,搜索可能的資源後仍然無法正常工作。Java非法參數異常android

錯誤:

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); 

FOR 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> 
+0

你可以發佈你的logcat嗎?由於聲譽有限, – PSK

+0

無法發佈logcat,謝謝 – user3243065

回答

0

你在if(!drawer.isDrawerOpen(expListView)) expListView名單越來越例外是不是一個抽屜。這就是爲什麼你越來越java.lang.IllegalArgumentException:

試試這個post你會得到一些想法。 欲瞭解更多信息link