异步请求时,向服务器传参,报空指针异常? 400 报错
public class ExpertFragment extends Fragment implements OnClickListener {
private View view;
// private int currentUI = 0; // 0 专家咨询页面 , 1 专家排行页面
private XListView mLv;
private LinearLayout mLinearBottom;
private ImageView mImgLine;
private TextView mOnlineConsultantTxt, mExpertRankingTxt;
private ArrayList<ExpertConsult> mConsultList = new ArrayList<ExpertConsult>();
public ArrayList<ExpertRanking> mRankingList = new ArrayList<ExpertRanking>();
private ExpertConsultAdapter mConsultAdapter;
public ExpertRankingAdapter mRankingAdadpter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_expert, null);
initView(view);
initData();
return view;
}
// 初始化控件以及为其设置监听事件
private void initView(View view) {
// mTitle = (TitleView) findViewById(R.id.titleview);
// mTitle.setBack(new TitleView.ViewBack() {
// @Override
// public void onViewBack() {
// finish();
// }
// });
// mTitle.setTVTitle("在线咨询");
mLinearBottom = (LinearLayout) view.findViewById(R.id.linearbottom);
mImgLine = (ImageView) view.findViewById(R.id.imgline);
mLv = (XListView) view.findViewById(R.id.experlist);
// 去掉listview下面的线(或者用mConsultLv.setDivider(null);)
mLv.setDividerHeight(0);
// 去掉点击listview时,所显示的背景颜色
mLv.setCacheColorHint(0);
// mLv.setPullRefreshEnable(true);// 设置下拉刷新
// mLv.setXListViewListener(this);// 设置监听事件,重写两个方法
mLv.setPullLoadEnable(false);// 设置上拉刷新
mOnlineConsultantTxt = (TextView) view
.findViewById(R.id.txtonlineconsultant);
mExpertRankingTxt = (TextView) view.findViewById(R.id.txtexpertranking);
mOnlineConsultantTxt.setOnClickListener(this);
mExpertRankingTxt.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.txtonlineconsultant:
// mTitle.setTVTitle("在线咨询");
mOnlineConsultantTxt.setBackgroundColor(getResources().getColor(
R.color.view_grey));
mOnlineConsultantTxt.setTextColor(getResources().getColor(
R.color.main_bg));
mExpertRankingTxt.setBackgroundColor(getResources().getColor(
R.color.main_grey));
mExpertRankingTxt.setTextColor(Color.parseColor("#333333"));
mImgLine.setVisibility(View.GONE);
mLinearBottom.setVisibility(View.GONE);
// 刷新适配器 在线咨询
if (mConsultList.size() == 0) {
getOnlineConsultant();
} else {
mLv.setAdapter(mConsultAdapter);
}
break;
case R.id.txtexpertranking:
// mTitle.setTVTitle("专家排行");
mExpertRankingTxt.setBackgroundColor(getResources().getColor(
R.color.view_grey));
mExpertRankingTxt.setTextColor(getResources().getColor(
R.color.main_bg));
mOnlineConsultantTxt.setBackgroundColor(getResources().getColor(
R.color.main_grey));
mOnlineConsultantTxt.setTextColor(Color.parseColor("#333333"));
mImgLine.setVisibility(View.VISIBLE);
mLinearBottom.setVisibility(View.VISIBLE);
// 刷新适配器 专家排行
if (mRankingList.size() == 0) {
getExpertRanking();
} else {
mLv.setAdapter(mRankingAdadpter);
}
break;
default:
break;
}
}
public void initData() {
// TODO Auto-generated method stub
getOnlineConsultant();
}
/**
* 加载更多数据
*/
private void loadMoreData() {
mConsultAdapter.mConsultList.get(
mConsultAdapter.mConsultList.size() - 1).getId();
}
private void onLoad() {
mLv.stopRefresh();
mLv.stopLoadMore();
mLv.setRefreshTime(TimeUtil.getTime());
}
// 在线咨询
private void getOnlineConsultant() {
// lastid 最后一条id
List<HashMap<String, String>> parameters = MyUtils
.getNetListParameters(
new String[] { "lastid" },
new String[] { mConsultAdapter.mConsultList.get(
mConsultAdapter.mConsultList.size() - 1)
.getId() });
new NetAsyncTask(getActivity(), ExpertConsult.class,
new TypeToken<List<ExpertConsult>>() {
}.getType(), new NetAsyncTask.AsyncThreadInter() {
@Override
public void onPreExecute() {
// TODO Auto-generated method stub
}
@Override
public void onExecuteOK(Object o) {
mConsultList.clear();
List<ExpertConsult> list = (List<ExpertConsult>) o;
mConsultList.addAll(list);
if (mConsultAdapter == null) {
mConsultAdapter = new ExpertConsultAdapter(
getActivity(), mConsultList);
}
mLv.setAdapter(mConsultAdapter);
mConsultAdapter.refreshAdapter(mConsultList);
mLv.setPullLoadEnable(true);
// mLv.stopLoadMore();
onLoad();
}
@Override
public void onExecuteFail(String errorInfo) {
// TODO Auto-generated method stub
}
}, parameters).execute("getconsultinglistforpage");
}
// 专家排行
private void getExpertRanking() {
// List<HashMap<String, String>> parameters = MyUtils
// .getNetListParameters(new String[] { "" }, new String[] { "" });
new NetAsyncTask(getActivity(), ExpertRanking.class,
new TypeToken<List<ExpertRanking>>() {
}.getType(), new NetAsyncTask.AsyncThreadInter() {
@Override
public void onPreExecute() {
// TODO Auto-generated method stub
}
@Override
public void onExecuteOK(Object o) {
// TODO Auto-generated method stub
mRankingList.clear();
List<ExpertRanking> list = (List<ExpertRanking>) o;
mRankingList.addAll(list);
if (mRankingAdadpter == null) {
mRankingAdadpter = new ExpertRankingAdapter(
getActivity(), mRankingList);
}
mLv.setAdapter(mRankingAdadpter);
mRankingAdadpter.refreshAdapter(mRankingList);
}
@Override
public void onExecuteFail(String errorInfo) {
// TODO Auto-generated method stub
}
}, null).execute("getExperterRanking");
}
}
【-------List<HashMap<String, String>> parameters = MyUtils
.getNetListParameters(
new String[] { "lastid" },
new String[] { mConsultAdapter.mConsultList.get(
mConsultAdapter.mConsultList.size() - 1)
.getId() });-----------】这段代码报空指针异常
请各位大神们指教!!!!!谢谢各位啦!
debug模式下,跟踪看看到底是哪个对象是null,很容易就找到问题了######你都不如把异常贴出来……######嗯嗯,谢谢您! ######
【-------List<HashMap<String, String>> parameters = MyUtils
.getNetListParameters(
new String[] { "lastid" },
new String[] { mConsultAdapter.mConsultList.get(
mConsultAdapter.mConsultList.size() - 1)
.getId() });-----------】这段代码报空指针异常
就是传参的时候报空指针,冒昧的问一句,可以加一下您的QQ吗?
###### 代码这里报空指针异常: List<HashMap<String, String>> parameters = MyUtils
.getNetListParameters(
new String[] { "lastid" },
new String[] { mConsultAdapter.mConsultList.get(
mConsultAdapter.mConsultList.size() - 1)
.getId() });
mLv.setPullLoadEnable(true);
// mLv.stopLoadMore();
onLoad();
}
传参数为:parameters
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。