2

The following lines within a Fragment are throwing an exception for which I am unable to find the root cause.

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_player_pane, container, false);
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) rootView.getLayoutParams();

    // set width height
    params.height = (getArguments().getInt(HEIGHT));
    params.width = (getArguments().getInt(WIDTH));

    fragmentHeight = (getArguments().getInt(HEIGHT));
    fragmentWidth = (getArguments().getInt(WIDTH));

    // substitute parameters for left,top, right, bottom, (All 4 not necessary)
    params.setMargins((getArguments().getInt(LEFT_MARGIN)),
            (getArguments().getInt(TOP_MARGIN)),
            (getArguments().getInt(RIGHT_MARGIN)),
            (getArguments().getInt(BOTTOM_MARGIN)));

    youTubePlayerNecessary = getArguments().getBoolean(REQUIRE_YOUTUBE);
    rotate = getArguments().getBoolean(REQUIRE_ROTATION);
    muteAudio = getArguments().getBoolean(MUTE_AUDIO);

    rootView.setLayoutParams(params);

    return rootView;
}

Exception:

11-02 11:36:04.966 3440-3452/com.blynq.app.multipaneplayer E/StrictMode: 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 java.io.RandomAccessFile.<init>(RandomAccessFile.java:127)
        at com.android.webview.chromium.WebViewChromiumFactoryProvider.startChromiumLocked(WebViewChromiumFactoryProvider.java:16107)
        at com.android.webview.chromium.WebViewChromiumFactoryProvider.ensureChromiumStartedLocked(WebViewChromiumFactoryProvider.java:333)
        at com.android.webview.chromium.WebViewChromiumFactoryProvider.startYourEngines(WebViewChromiumFactoryProvider.java:427)
        at com.android.webview.chromium.WebViewChromium.init(WebViewChromium.java:162)
        at android.webkit.WebView.<init>(WebView.java:554)
        at android.webkit.WebView.<init>(WebView.java:489)
        at android.webkit.WebView.<init>(WebView.java:472)
        at android.webkit.WebView.<init>(WebView.java:459)
        at java.lang.reflect.Constructor.newInstance(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
        at android.view.LayoutInflater.createView(LayoutInflater.java:607)
        at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
        at com.blynq.app.fragments.PlayerPane.onCreateView(PlayerPane.java:181)
        at android.app.Fragment.performCreateView(Fragment.java:2053)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
        at android.app.BackStackRecord.run(BackStackRecord.java:834)
        at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1454)
        at android.app.FragmentManagerImpl$1.run(FragmentManager.java:447)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5343)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)

I am currently running app in debug mode to check all possible memory leaks.

if (BuildConfig.DEBUG) {
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                .detectAll()
                .penaltyLog()
                .penaltyDeath()
                .build());
    }

All tags in manifest file are properly closed too. I am unable to figure out which resource was left open without being handled. How do I resolve this ?

P.S. I have referred to thread before asking the question, which is a very generic question offering no new necessary insight for me. This question is very specific to the details mentioned above, here I am seeking help to find which resource is causing the leak..

Community
  • 1
  • 1
jay
  • 1,982
  • 2
  • 24
  • 54
  • 1
    Check your manifest file and confirm if all your tags are properly closed, if you are using okHttp, then it's a known bug for older version. Update it to a newer version – Shashank Udupa Nov 02 '16 at 06:24
  • Yes, all tags in manifest file are properly closed. I am not using okHttp within my project, using `org.apache.httpcomponents:httpclient-android:4.3.5.1` for http communications – jay Nov 02 '16 at 06:36
  • post complete fragment_player_pane and oncreateview method – Umar Ata Nov 02 '16 at 06:55
  • check whether your tag in manifest is enclosed within tag . – Rajesh Gosemath Nov 02 '16 at 07:19
  • @Umar - Added more detail, please check – jay Nov 02 '16 at 08:11
  • what are you trying to achieve first getting layour params from rootview then adding the same to same rootview object – Umar Ata Nov 02 '16 at 08:15
  • Possible duplicate of [A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks](http://stackoverflow.com/questions/25544021/a-resource-was-acquired-at-attached-stack-trace-but-never-released-see-java-io) – Umar Ata Nov 02 '16 at 08:23
  • @jay Hi, did you figure out what causes the problem? – Tefa Mar 16 '18 at 01:03

2 Answers2

2

Somebody raised an issue for this here: https://code.google.com/p/android/issues/detail?id=226751

I've been having the same issue, and it looks like it's a bug in API < 25. Try your program in an emulator with API 25 and see if it works. If it works there, then it is most likely the same problem and you are out of luck until is able to fix the issue.

RoyMars
  • 21
  • 1
0
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog()
                                .penaltyDeath().build());

For more Information Follow this Url Error Solve Url

Community
  • 1
  • 1
Ashish
  • 371
  • 3
  • 18