0
我正在開發Google Play中的應用程序。 我的應用程序有 「谷歌分析」,我看到異常:在AsyncTask中檢查值的NullPointerException
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);
}
}
}
後整個堆棧跟蹤 –
以及周圍的任何代碼(即,如果的AsyncTask是另一個類中,提供該類) –
@Unmerciful請發佈與問題相關的完整代碼,然後,它可以幫助我們理解根本原因,** FYI **只是檢查您是否在onPo之前初始化** feed **變量st方法被調用。 – swiftBoy