2012-03-07 58 views
0

嗨刚刚得到一个错误,我不知道为什么任何人都可以帮忙?Android的setlistAdapter错误

这是我的JSON提要是如何构成的,我想这个消息阵列

{ “代码”:200, “错误”:空, “数据”:{ “新闻”:[{ “news_id”:” 8086“ 我在这里得到一个错误:在oneOjectsItem

setListAdapter(new ArrayAdapter(this,R.layout.single_item,oneObjectsItem));

这里我的代码

 // Instantiate a JSON object from the request response 
     JSONObject jsonObject = new JSONObject(json); 



     JSONArray jArray = jsonObject.getJSONArray("news"); 


     for (int i=0; i < jArray.length(); i++) 
     { 
      JSONObject oneObject = jArray.getJSONObject(i); 
      // Pulling items from the array 
      String oneObjectsItem = oneObject.getString("title"); 



     } 


    } catch(Exception e){ 
     // In your production code handle any errors and catch the individual exceptions 
     e.printStackTrace(); 
    } 




    setListAdapter (new ArrayAdapter<String>(this, R.layout.single_item, oneObjectsItem)); 



ListView list = getListView(); 
list.setTextFilterEnabled(true); 
list.setOnItemClickListener(new OnItemClickListener(){ 

    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, 
      long arg3) { 
     // TODO Auto-generated method stub 
     Toast.makeText(getApplicationContext(), ((TextView) arg1).getText(),1000).show(); 
    } 



}); 

} 
+0

你得到的错误是什么? – jmishra 2012-03-07 23:07:31

+0

如果出现错误,请给出日志。或者,它是第一次加载? – dcanh121 2012-03-08 00:06:22

回答

0

使用setListAdapter initiliazing列表元素之后。你可以找到详细的样本here.

+0

它得到了一个红色的oneObjectsItemUnderlined,当点击它告诉我创建字段。但是这也不起作用 – iamlukeyb 2012-03-08 07:07:40