我正在做一个新闻app.But,当我在ListFragment中实现OnSendResultInterface时遇到空指针异常.Below是我的List片段。方法是sendResult。
public class ListFragment extends Fragment implements OnItemClickListener,
OnSendResultInterface {
private ListView mListview;
private OnItemPressListener mItempressed;
@Override
public void onAttach(Activity activity) {
.......
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
..........
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
if (null != mItempressed) {
mItempressed.OnItemPress(position);
}
}
@Override
public void sendResult(List<Entry> result) {
Log.v("result", "result" + result);
RssAdapter adapter = new RssAdapter(getActivity(), result);
mListview.setAdapter(adapter);
}
}
这是我的DownloadXmlTask.In这个类我初始化界面并声明方法。
public class DownloadXmlTask extends AsyncTask<String, Void, List<Entry>> {
private OnSendResultInterface mSendResult;<---this is the listener
@Override
protected List<Entry> doInBackground(String... urls) {
.......
}
@Override
protected void onPostExecute(List<Entry> result) {
if (null != result)
mSendResult.sendResult(result); <----null pointer exception shown here.
}
public List<Entry> downloadUrl(String urlString) throws IOException {
..........
}
}
答案 0 :(得分:0)
mSendResult变量未在任何地方初始化。