2016-12-26 39 views
0

我正在嘗試將數據發送到MySQL數據庫,但發生此錯誤。Android連接錯誤:Gralloc管道發生故障

W/gralloc_ranchu: Gralloc pipe failed 

[ 12-26 22:08:05.136 2393: 2393 D/   ] 
        HostConnection::get() New Host Connection established 0xa998dd80, tid 2393 

這裏是我的Android代碼

public RequestQueue reguestQueue; 
public String insertUrl = "10.0.2.2/beacon/insertBeacon.php"; // local ip adresi yaz 

private Handler mHandler = new Handler(); 

    private void startTime() { 
     mHandler.removeCallbacks(mUpdateTimeTask); 
     mHandler.postDelayed(mUpdateTimeTask, 100); 
    } 

    private Runnable mUpdateTimeTask = new Runnable() { 
     public void run() { 
      // buraya ne yapmak istiyorsan o kodu yaz.. Kodun sonlandıktan sonra 1 saniye sonra tekrar çalışacak şekilde handler tekrar çalışacak. 
      StringRequest request = new StringRequest(Request.Method.POST, insertUrl, new Response.Listener<String>() { 
       @Override 
       public void onResponse(String response) { 

        System.out.println(response.toString()); 
       } 
      }, new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError error) { 

       } 
      }) { 

       @Override 
       protected Map<String, String> getParams() throws AuthFailureError { 
        Map<String,String> parameters = new HashMap<String, String>(); 
        parameters.put("firstname","Serkan"); 
        parameters.put("lastname","BAYRAM"); 
        parameters.put("age","19"); 

        return parameters; 
       } 
      }; 
      reguestQueue.add(request); 
      mHandler.postDelayed(this, 1000); 
     } 
    }; 

回答

0

試試這個

 InputStream iss = null; 
     int code; 
     int done = 0; 
     String result = null; 

     ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 

     nameValuePairs.add(new BasicNameValuePair("firstname", "Serkan")); 
     nameValuePairs.add(new BasicNameValuePair("lastname", "BAYRAM")); 
     nameValuePairs.add(new BasicNameValuePair("age", "19")); 

     try { 
      HttpClient httpclient = new DefaultHttpClient(); 
      HttpPost httppost = new HttpPost("10.0.2.2/beacon/insertBeacon.php"); 
      httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8")); 
      HttpResponse response = httpclient.execute(httppost); 
      HttpEntity entity = response.getEntity(); 
      iss = entity.getContent(); 
     } catch(Exception e) { 
      Log.e("pass 2", "Connection Error"); 
      e.printStackTrace(); 
     } 

     try { 
      BufferedReader reader = new BufferedReader 
        (new InputStreamReader(iss,"iso-8859-1"),8); 
      StringBuilder sb = new StringBuilder(); 
      while ((line = reader.readLine()) != null) 
       sb.append(line + "\n"); 
      iss.close(); 
      result = sb.toString(); 
     } catch(Exception e) { 
      e.printStackTrace(); 
     } 

     try { 
      JSONObject json_data = new JSONObject(result); 
      code=(json_data.getInt("code")); 

      if(code==1){ 
       done = 1; //values inserted successfully 
      } 
      else 
       done = 0; //values not inserted successfully 
     } catch(Exception e) { 
      e.printStackTrace(); 
     } 

JSON格式返回1或0,從insertBeacon.php