2015-10-20 49 views
0

我正在嘗試構建一個應用程序,以通知無法訪問網絡上的信息的人。我已經完成了90%,所有即將到來的錯誤都得到了解決。當我啓動並點擊微調值時,我的應用程序崩潰。致命例外:AsyncTask#1 - Android應用程序在點擊微調時崩潰

我的日誌貓:

10-20 20:38:57.298 13722-13742/trial.spinners E/Surface: getSlotFromBufferLocked: unknown buffer: 0xab98af70 
10-20 20:38:58.966 13722-13722/trial.spinners E/ANAME =: sector-18 
10-20 20:38:59.001 13722-15968/trial.spinners E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1 
10-20 20:38:59.001 13722-15968/trial.spinners E/AndroidRuntime: Process: trial.spinners, PID: 13722 
10-20 20:38:59.001 13722-15968/trial.spinners E/AndroidRuntime: java.lang.RuntimeException: An error occurred while executing doInBackground() 
10-20 20:38:59.001 13722-15968/trial.spinners E/AndroidRuntime:  at android.os.AsyncTask$3.done(AsyncTask.java:309) 
10-20 20:38:59.001 13722-15968/trial.spinners E/AndroidRuntime:  at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354) 

public class ServerRequests { 
ProgressDialog progressDialog; 
public static final int CONNECTION_TIMEOUT = 15000; 
public static final String SERVER_ADDRESS = "http://kamster.net16.net/"; 


public ServerRequests(Context context) 
{ 
    progressDialog = new ProgressDialog(context); 
    progressDialog.setCancelable(false); 
    progressDialog.setTitle("Processing"); 
    progressDialog.setMessage("Please wait.."); 

} 


public void fetchDataInBackground(Contact contact , GetUserCallback callback) 
{ 
    progressDialog.show(); 
    new FetchDataAsyncTask(contact, callback).execute(); 


} 

public class FetchDataAsyncTask extends AsyncTask<Void , Void , Contact> 
{ 
    Contact contact; 
    GetUserCallback callback; 
    Contact returnedContact; 

    public FetchDataAsyncTask(Contact contact , GetUserCallback callback) 
    { 
     this.contact = contact; 
     this.callback = callback; 
    } 

    @Override 
    protected Contact doInBackground(Void... voids) { 
     ArrayList<NameValuePair> data_to_send = new ArrayList<NameValuePair>(); 
     data_to_send.add(new BasicNameValuePair("areaname" , contact.areaname)); 
     data_to_send.add(new BasicNameValuePair("distance" , contact.distance)); 

     HttpParams httpRequestParams = new BasicHttpParams(); 
     HttpConnectionParams.setConnectionTimeout(httpRequestParams , CONNECTION_TIMEOUT); 
     HttpConnectionParams.setSoTimeout(httpRequestParams , CONNECTION_TIMEOUT); 

     HttpClient client = new DefaultHttpClient(httpRequestParams); 
     HttpPost post = new HttpPost(SERVER_ADDRESS + "newInput.php"); 

     // Contact returnedContact = null; 
     try { 
      post.setEntity(new UrlEncodedFormEntity(data_to_send)); 
      HttpResponse httpResponse = client.execute(post); 

      HttpEntity entity = httpResponse.getEntity(); 
      String result = EntityUtils.toString(entity); 

      try { 
       JSONObject jsonObject = new JSONObject(result); 
       returnedContact = null; 

       if (jsonObject.length() == 0) { 
        returnedContact = null; 

       } else { 
        // String areaname,distance; 
        // areaname = null; 
        // distance=null; 

        // if(jsonObject.has("areaname")) 
        // areaname = jsonObject.getString("areaname"); 
        // if(jsonObject.has("distance")) 
        // distance =jsonObject.getString("distance"); 

        // returnedContact = new Contact(areaname,distance); 
        returnedContact = new Contact(contact.areaname, contact.distance); 

       } 
      }catch(JSONException jE){ 
       jE.printStackTrace(); 
      } 

     } 
     catch(IOException e) 
     { 
      e.printStackTrace(); 
     } 

     return returnedContact; 
    } 
    @Override 
    protected void onPostExecute(Contact returnedContact) { 
     progressDialog.dismiss(); 
     callback.done(returnedContact); 
     super.onPostExecute(returnedContact); 
    } 

} 
} 
+0

你不必調用'super.onPostExecute(...)',但它看起來像你的錯誤是從你的'doInBackground'方法產生的,所以我會逐步通過它,看看它在哪裏破壞 – ElliotM

+0

謝謝很多@ElliotM我做了你的建議,但我無法理解doinbackgroud方法有什麼問題,你能不能展示一些光... –

+0

嘗試調試和步進通過,同時google解決方案'getSlotFromBufferLocked:unknown buffer' – ElliotM

回答