2013-04-03 3 views
9

नहीं कहा जाता है, मुझे एक स्ट्रिक्टोड विफलता दिखाई दे रही है, और मैं नहीं देख सकता कि मैं क्या कर रहा हूं। विफलता है:एंड्रॉइड स्ट्रिक्टोड थ्रोबल: स्पष्ट समाप्ति विधि 'अंत' को

java.lang.Throwable: Explicit termination method 'end' not called 
    E/StrictMode(26875): at dalvik.system.CloseGuard.open(CloseGuard.java:184) 
    E/StrictMode(26875): at java.util.zip.Inflater.<init>(Inflater.java:82) 
    E/StrictMode(26875): at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:96) 
    E/StrictMode(26875): at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:81) 
    E/StrictMode(26875): at libcore.net.http.HttpEngine.initContentStream(HttpEngine.java:528) 
    E/StrictMode(26875): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:836) 
    E/StrictMode(26875): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274) 
    E/StrictMode(26875): at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:486) 
    E/StrictMode(26875): at com.mycompany.MyClass.sendJson(MyClass.java:267) 

मैं StrictMode कॉन्फ़िगर करें:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() 
       .detectLeakedSqlLiteObjects().detectLeakedClosableObjects().penaltyLog() 
        .penaltyDeath().build()); 
} 

कोड तरह दिखता है निम्नलिखित:

HttpURLConnection connection = null; 
OutputStream outputStream = null; 
InputStream in = null; 

try { 
     connection = (HttpURLConnection)new URL("http://our.server/some/path").openConnection(); 

     connection.setRequestProperty("Accept", "application/json"); 
     connection 
       .setRequestProperty("Content-Type", "application/json; charset=UTF-8"); 
     connection.setDoOutput(true); 

     outputStream = connection.getOutputStream(); 

     String content = "{\"some\":\"json data\"}"; 
     byte bytes[] = content.getBytes("UTF-8"); 
     outputStream.write(bytes); 
     outputStream.flush(); 

     responseCode = connection.getResponseCode(); // This is line 267 in the stack trace 

     if (HttpURLConnection.HTTP_OK == responseCode 
       || HttpURLConnection.HTTP_CREATED == responseCode) { 

      // do something with a successful response 
     } 
    } 

} catch (IOException e) { 
    // report the exception 
} finally { 
    if (null != connection) { 
     connection.disconnect(); 
    } 
    if (null != outputStream) { 
     try { 
      outputStream.close(); 
     } catch (IOException e) { 
     } 
    } 
    if (null != in) { 
     try { 
      in.close(); 
     } catch (IOException e) { 
     } 
    } 
} 

मैं एक ही StrictMode विफलता को देखकर की शिकायत जब गूगल का उपयोग कर किसी को पाया AdMob SDK (https://groups.google.com/forum/?fromgroups=#!topic/google-admob-ads-sdk/yVss4ufdPp4) लेकिन मुझे अब तक कोई समाधान नहीं मिला है।

+0

(gziped HTTP प्रतिक्रिया पर) की कोशिश की, लेकिन अपवाद को पुन: उत्पन्न नहीं कर सकता। क्या आप एक स्पष्ट [सख्त मोड नीति] स्थापित कर रहे हैं (http://developer.android.com/reference/android/os/StrictMode.html)? आपका एंड्रॉइड एसडीके संस्करण क्या है? – minipif

+0

मैंने यह दिखाने के लिए प्रश्न संपादित किया है कि मैं StrictMode –

+0

को कॉन्फ़िगर कर रहा हूं क्या आपको कभी इसका समाधान मिला? मेरे लिए यह एंड्रॉइड के GZIPInputStream में एक बग जैसा दिखता है, क्योंकि यह एक इन्फ्लैटर बनाता है, "एंड" के लिए एक करीबी गार्ड पंजीकृत करता है, लेकिन फिर कभी अंततः कॉल नहीं करता है। – Matthias

उत्तर

3

क्या होता है यदि आपको प्रतिक्रिया स्ट्रीम मिलती है, इसे पूरी तरह से पढ़ें और इसे बंद करें (भले ही प्रतिक्रिया कोड ठीक नहीं है)।
मुझे लगता है कि इस HttpEngine.release() लागू करेगा, और इस तरह अपवाद है जब GzipInputStream बाद में अंतिम रूप दे दिया है (के रूप में अपवाद निर्माता में तैयार लेकिन finalize() में throwed है)

+1

मैं इसे जाने दूंगा ... –

+0

यह आशाजनक लग रहा था, लेकिन यह मेरे लिए जोनाथन के समान टुकड़े में काम नहीं करता था। नेक्सस एस –

+0

पर 4.1.2 के साथ परीक्षण किया गया है दिलचस्प [एक सुझाव और फिक्स] (https://github.com/square/okhttp/pull/24/files#diff-a717786a862ad3d4b9846a5168428cc9R96) [okhttp] में (https://github.com/square/okhttp)। –

2

से बचने मुझे लगता है कि connection.getResponseCode() एक इनपुट स्ट्रीम खोलता है। तो आपको इनपुट स्ट्रीम को पुनर्प्राप्त करने और इसे बंद करने की आवश्यकता होगी।

+1

इसने मेरी समान स्ट्रिक्टोड समस्या को हल किया! धन्यवाद!! कोड स्निपेट: connection.getInputStream()। बंद करें() –

+0

@ पैनीनी लंचर धन्यवाद यह मेरे लिए काम करता है। मुझे यह मिल रहा है क्योंकि 'connection.getContentLength() '। इस। – Dharmishtha

संबंधित मुद्दे