2014-05-09 80 views
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); 
    } 
} 

}

+0

後整個堆棧跟蹤 –

+0

以及周圍的任何代碼(即,如果的AsyncTask是另一個類中,提供該類) –

+2

@Unmerciful請發佈與問題相關的完整代碼,然後,它可以幫助我們理解根本原因,** FYI **只是檢查您是否在onPo之前初始化** feed **變量st方法被調用。 – swiftBoy

回答

0

請更新您onPostExecute方法這種方法並再次測試

protected void onPostExecute(final Feed feed) 
{ 
    if(mFragmentCallback != null && feed != null) 
    { 
     mFragmentCallback.onTaskDone(feed); 
    } 
    else 
    { 
     //the value is null 
    } 
} 
相關問題