我先详细描述一下出现的问题:
1、出现错误的界面在AndroidManifest.xml中的注册如下:
<activity
android:name="com.yx.logistics.MainActivity"
android:configChanges="keyboardHidden|orientation"
android:launchMode="singleTop"
android:taskAffinity="com.yx.logistics.main"
android:screenOrientation="portrait" >
</activity>
2、界面的代码:
public class MainActivity extends FragmentActivity {
private static MainActivity thisRef;
// 未分配handler
/**
* 主要是用来获取列表的数据
*/
public static DownFileHandler wfphandler;
@SuppressLint("HandlerLeak")
class DownFileHandler extends Handler {
@Override
public void handleMessage(Message msg) {
if(msg.what==51){
lsv_wfp.onRefreshComplete();
tvxin1.setText("" + 0);
order_totil.setText("有" + 0 + "个订单未安排配送");
List<String> list = new ArrayList<String>();
list.add(msg.getData().getString("msg"));
//这里就是出错的地方 thisRef值为空。毫无疑问,我肯定是赋过值的。
EmptyAdapter empty = new EmptyAdapter(thisRef, list);
lsv_wfp.setAdapter(empty);
wjspageLoad.setVisibility(View.GONE);
return;
}
// 下单统计发来的消息
if (msg.what == 10) {
tv_sumcount.setText("共" + msg.arg1 + "单");
}
if (msg.what == 50) {
lsv_wfp.onRefreshComplete();
wjsisLoading = false;
Bundle bundle = msg.getData();
@SuppressWarnings("unchecked")
ArrayList<WLOrder> newlist = (ArrayList<WLOrder>) bundle
.getSerializable("orderlist");
sumcount = bundle.getInt("sumcount", 0);
tvxin1.setText("" + sumcount);
order_totil.setText("有" + sumcount + "个订单未安排配送");
LocationApplication.wjsnumber = sumcount;
totalnumber = totalnumber + newlist.size();
if ((newlist.size() == 0) && sumcount == 0) {
List<String> list = new ArrayList<String>();
list.add("对不起,没有订单");
//这里就是出错的地方 thisRef值为空。毫无疑问,我肯定是赋过值的。
EmptyAdapter empty = new EmptyAdapter(thisRef, list);
lsv_wfp.setAdapter(empty);
wjspageLoad.setVisibility(View.GONE);
return;
}
if (newlist != null && newlist.size() > 0) {
orderlistAdapter.refresh(newlist);
}
if ((page == 1 && sumcount <= WLOrderInfo.PAGENUMBER)
|| (totalnumber == sumcount)
|| (newlist.size() < WLOrderInfo.PAGENUMBER)
|| (newlist.size() == 0) || (newlist == null)) {
wjspageLoad.setVisibility(View.GONE);
}
}
}
}
……
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
thisRef = this;
wfphandler = new DownFileHandler();
……
}
……
}
3、EmptyAdapter的写法如下:
package com.yx.logistics.adapter;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.yx.logistics.R;
/**
* */
public class EmptyAdapter extends BaseAdapter {
List<String> list;
private Context context;
public EmptyAdapter(Context context, List<String> list) {
this.context = context;
this.list = list;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
@Override
public String getItem(int position) {
// TODO Auto-generated method stub
return list.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
VHolder holder;
if (convertView == null) {
holder = new VHolder();
convertView = LayoutInflater.from(context).inflate(
R.layout.empty_view, null);
holder.tv_left = (TextView) convertView.findViewById(R.id.tv_left);
convertView.setTag(holder);
}else{
holder=(VHolder) convertView.getTag();
}
holder.tv_left.setText(list.get(position));
return convertView;
}
class VHolder {
TextView tv_left;
}
}
-------------------------------------------------------------
找不到原因,我想不明白,为什么MainActivity这个界面明明存在,而thisRef这个值就为null。