2013-01-22 69 views
0

我正在檢索數據(用戶信息),並將其從HashMap分配到ArrayAdpater(在列表視圖中)。每當我點擊(或甚至滾動)listview我的應用程序崩潰。Android-Listview

任何想法爲什麼會發生?下面是我在做什麼:

//.. 
    Handler handler = new Handler(); 
@Override 
protected void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_app_activity3); 
    information=new String[50]; 
    Intent intent = getIntent(); 
    Custom custom = (Custom) intent.getSerializableExtra("custom"); 
    HashMap<String, String> list = custom.getList(); 
    //Set s = list.entrySet(); 
    Iterator items=list.values().iterator(); 
    int i=0; 
    while (items.hasNext()) 
    { 
     information[i]=(String) items.next(); 
     System.out.println(information[i]); 
     i++; 
    } 
    lv = (ListView)findViewById(R.id.listview1); 
    lv.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,information)); 
    lv.setTextFilterEnabled(true); 
} 

這裏是我的logcat:

01-22 22:45:20.286:d/AndroidRuntime(332):關閉VM 01-22 22 :45/20.286:W/dalvikvm(332):threadid = 1:線程退出與未捕獲的異常(組= 0x4001d800) 01-22 22:45:20.306:E/AndroidRuntime(332):致命例外:主 01- 22 22:45:20.306:E/AndroidRuntime(332):java.lang.NullPointerException 01-22 22:45:20.306:E/AndroidRuntime(332):at android.widget.ArrayAdapter.createViewFromResource (ArrayAdapter.java:355) 01-22 22:45:20.306:E/AndroidRuntime(332):at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323) 01-22 22:45:20.306:E/AndroidRuntime(332):at android.widget.AbsListView.obtainView(AbsListView.java:1294) 01-22 22:45:20.306:E/AndroidRuntime(332):at android.widget.ListView.measureHeightOfChildren(ListView.java :1198) 01-22 22:45:20.306:E/AndroidRuntime(332):at android.widget.ListView.onMeasure(ListView.java:1109) 01-22 22:45:20.306:E/AndroidRuntime(332 ):at android.view.View.measure(View.java:8171) 01-22 22:45:20.306:E/AndroidRuntime(332):at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 01-22 22:45:20.306:E/AndroidRuntime(332):在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012) 01-22 22:45:20.306:E/AndroidRuntime(332):at android.widget.LinearLayout.measureVertical(LinearLayout.java:381) 01-22 22:45:20.306:E/AndroidRuntime(332):at android.view.measure(View.java:8171) 01-22 22:45:20.306: 22:45:20.306:E/AndroidRuntime(332):在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 01-22 22:45:20.306:E/AndroidRuntime(332):在android.widget。 FrameLayout.onMeasure(FrameLayout.java:245) 01-22 22:45:20.306:E/AndroidRuntime(332):at android.view.View.measure(View.java:8171) 01-22 22:45: 20.306:E/AndroidRuntime(332):在android.widget.LinearLayout.measureVertical(LinearLayout.java:526) 01-22 22:45:20.30 6:E/AndroidRuntime(332):在android.widget.LinearLayout.onMeasure(LinearLayout.java:304) 01-22 22:45:20.306:E/AndroidRuntime(332):at android.view.View.measure View.java:8171) 01-22 22:45:20.306:E/AndroidRuntime(332):at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 01-22 22:45:20.306:E/AndroidRuntime(332):在android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 01-22 22:45:20.306:E/AndroidRuntime(332):at android.view.View.measure(View.java: 8171) 01-22 22:45:20.306:E/AndroidRuntime(332):at android.view.ViewRoot.performTraversals(ViewRoot.java:801) 01-22 22:45:20.306:E/AndroidRuntime(332) :at android.view.ViewRoot.handleMessage(ViewRoot.java:1727) 01-22 22:45:20.306:E/AndroidRuntime(332):at android.os.Handler.dispatchMessage(Han dler.java:99) 01-22 22:45:20.306:E/AndroidRuntime(332):at android.os.Looper.loop(Looper.java:123) 01-22 22:45:20.306:E/AndroidRuntime(332):at android.app.ActivityThread.main(ActivityThread.java:4627) 01-22 22:45:20.306:E/AndroidRuntime(332):at java.lang.reflect.Method.invokeNative(Native Method ) 01-22 22:45:20.306:E/AndroidRuntime(332):at java.lang.reflect.Method.invoke(Method。java:521) 01-22 22:45:20.306:E/AndroidRuntime(332):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868) 01-22 22:45: 20.306:E/AndroidRuntime(332):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 01-22 22:45:20.306:E/AndroidRuntime(332):at dalvik.system。 NativeStart.main(本地方法) 01-22 22:45:22.496:I /進程(332):發送信號。 PID:332 SIG:9

+5

發佈您的logcat錯誤報告.. –

+1

發佈listview的onclick事件代碼.. – Subburaj

+0

查看此代碼的listview示例:http://www.ezzylearning.com/tutorial.aspx?tid=1659127 – krishna

回答

0
ListView lv = (listView) findViewById(R.Id.listView1); 

進一步定義你的ListView。

相關問題