SimpleAdapter的setAdapter()失败,logcat找不到原因,求大神!解决办法
SimpleAdapter的setAdapter()失败,logcat找不到原因,求大神!!!
从远程服务器提取订单显示,前面都测试通过,setAdapter却始终不行。
代码如下:
下面是layout文件的代码:
------解决方案--------------------
空指针?莫非orderListView没绑定ID,不是我想问下这个变量名可以这样定义吗?
------解决方案--------------------
断点调试,看看哪里报空指针 是orderListView 还是R.layout.index_order
从远程服务器提取订单显示,前面都测试通过,setAdapter却始终不行。
代码如下:
/*
* 获取服务器订单
* @param String url, HashMap<String,Object> data
* @void
*/
public void getOrders(String url,HashMap<String,Object> param) throws Exception
{
String data = RedefineHttpRequest.HttpPost(url, param); //取得服务器返回的json
JSONObject msg = new JSONObject(data);
int error = msg.getInt("error");
switch (error)
{
case 0: //返回正确
JSONArray arr = msg.getJSONArray("data");
if(arr.length()==0) //订单数组为空
{
}
else
{
List<HashMap<String,Object>> res = new ArrayList<HashMap<String,Object>>(); //定义订单集合数组
for(int i=0;i<arr.length();i++)
{
HashMap<String,Object> map = new HashMap<String,Object>();
JSONObject order = arr.getJSONObject(i); //取得每一个订单
map.put("order_id", order.getInt("order_id"));
map.put("goods_name",order.getString("goods_name"));
map.put("amount", order.getDouble("amount"));
res.add(map); //添加到集合数组
}
SimpleAdapter _Adapter = new SimpleAdapter(this.getActivity(), res ,R.layout.index_order,
new String[]{"order_id"},
new int[]{R.id.order_id}
);
try
{
orderListView.setAdapter(_Adapter); //执行失败,编译通过
}
catch(Exception e)
{
android.util.Log.i("notice",e.toString());
}
}
break;
case 1: //返回错误
break;
case 2: //未登录
break;
}
}
下面是layout文件的代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView android:id="@+id/order_id"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#55555555"
/>
</RelativeLayout>
------解决方案--------------------
空指针?莫非orderListView没绑定ID,不是我想问下这个变量名可以这样定义吗?
------解决方案--------------------
断点调试,看看哪里报空指针 是orderListView 还是R.layout.index_order