我正在Google Play中开发应用。 我的应用有#34; Google Analytics"我在例外中看到:
NullPointerException(@AsyncDownload:onPostExecute:70)
问题出在哪里?
public class AsyncDownload extends AsyncTask<String, Void, Feed > {
private FragmentCallback mFragmentCallback;
public AsyncDownload(FragmentCallback fragmentCallback) {
mFragmentCallback = fragmentCallback;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(String... arg0) {
Feed feed = ArticlesManager.getInstance().getFeed(arg0[0]);
if(feed==null){
try {
HttpGet get = new HttpGet(Ipsum.Headlines[Integer.valueOf(arg0[0])][2]);
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 3000);
HttpConnectionParams.setSoTimeout(httpParameters, 5000);
HttpClient hc = new DefaultHttpClient();
HttpResponse rp = hc.execute(get);
if (rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
String res = EntityUtils.toString(rp.getEntity(),HTTP.UTF_8);
Feed feed = RssReader.read(res,Integer.valueOf(arg0[0]) == 7);
ArticlesManager.getInstance().addFeed(arg0[0], feed);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
protected void onPostExecute(final Feed feed){
if(mFragmentCallback != null) {
mFragmentCallback.onTaskDone(feed);
}
}
}
答案 0 :(得分:0)
请以这种方式更新 onPostExecute 方法并再次测试
protected void onPostExecute(final Feed feed)
{
if(mFragmentCallback != null && feed != null)
{
mFragmentCallback.onTaskDone(feed);
}
else
{
//the value is null
}
}