2017-09-18 22 views
1

我遇到了資源泄漏問題,有人可以告訴我最新版本的代碼有什麼問題。我一直在從幾個小時發現,沒有什麼可以幫助解決它。 我已經寫了這個代碼在適配器類。當我點擊完成的textview時,我得到資源泄漏。資源是在附加的堆棧跟蹤中獲取的,但從未發佈

completed.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      final String serverURL = PathUrls.pathUrl + "evs_updatedeliverystatus.php?db=" + companyName.getString("companyName", "") + "&invoiceid=" + dlb.getInvoiceNo() + "&deliverystatus=3&time=noneed"; 
      Log.d("completed order URL", serverURL); 
      JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(serverURL, new Response.Listener<JSONObject>() { 
       @Override 
       public void onResponse(JSONObject response) { 
        Log.d("badOrder", response.toString()); 
        if (response.length() > 0) { 
         VolleyLog.v("badOrder", response.toString()); 
         try { 
          int status = response.getInt("status"); 
          if (status == 1) { 
           Log.d("Update BadOrderList ", response.toString()); 
           deliveryListBeans.remove(position); 
           notifyDataSetChanged(); 
           Toast.makeText(ct, "Order is completed", Toast.LENGTH_LONG).show(); 
          } else if (status == 0) { 
           Toast.makeText(ct, "Order Not completed ", Toast.LENGTH_LONG).show(); 
          } 
         } catch (JSONException ex) { 
          ex.printStackTrace(); 
         } 
        } 
       } 
      }, new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError error) { 
        error.printStackTrace(); 
        VolleyLog.e("Error in completing order:%n %s ", error); 
        Toast.makeText(ct, "NetworkError Not Responding", Toast.LENGTH_SHORT).show(); 
       } 
      }); 
      VolleySingleton.getsInstance().getRequestQueue().add(jsonObjectRequest); 

     } 
    }); 

我收到以下錯誤

A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks. 
    java.lang.Throwable: Explicit termination method 'close' not called 
    at dalvik.system.CloseGuard.open(CloseGuard.java:184) 
    at android.database.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:170) 
    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:190) 
    at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463) 

VolleySingleton類

public class VolleySingleton { 
private static VolleySingleton sInstance=null; 
private RequestQueue mRequestQueue; 
private VolleySingleton() 
{ 
    mRequestQueue= Volley.newRequestQueue(MyApplication.getAppContext()); 
} 
public static VolleySingleton getsInstance() 
{ 
    if (sInstance==null) 
    { 
     sInstance=new VolleySingleton(); 

    } 
    return sInstance; 
} 
public RequestQueue getRequestQueue() 
{ 
    return mRequestQueue; 
} 

}

我使用的是volleySingleton類。

+0

發表您的android.database.sqlite.SQLiteConnection。類也 – Anonymous

+0

@Anonymous我正在使用凌空單身類 –

回答

0

嘗試添加這一個在您的響應

finally 
{ 
    response.body().close(); 
} 
+0

什麼是'body()'方法?響應後我沒有獲得'body()'。 –

+0

你在任何地方使用sqlite嗎? – Anonymous

相關問題