Showing posts with label IllegalStateException. Show all posts
Showing posts with label IllegalStateException. Show all posts

java.lang.illegalstateexception: unable to create layer for linearlayout

Found most of this crashes on Android 6.0 around 75% of the total crashes and 25% from Android 5.0. According to google Crashlytics  report, these devices areOnePlus One, OnePlus X, Xperia Z, Xperia Z1, Xperia Z2, Xperia Z3, Samsung Galaxy Note, Galaxy S4 and Galaxy S5 devices, covering 80% of total crashes. Not able to recreate this crash on my HTC, Mi devices. How to reproduce this issue or find where exact the issue in app? Below is the detailed log from Crashlytics.
Fatal Exception: java.lang.IllegalStateException: Unable to create layer for LinearLayout, size 1080x4160 exceeds max size 4096
       at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
       at android.os.MessageQueue.next(MessageQueue.java:323)
       at android.os.Looper.loop(Looper.java:136)
       at android.app.ActivityThread.main(ActivityThread.java:6186)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

Rectify and solve issue:

I have Nested scroll view which contains vertical recycler view and other elements in the main screen.

What is the exact issue :
Cause is that RecyclerView inside scrollview or nestedscrollview try to load all items at once. As RecyclerView loads all items, also those items whcih are not visible. If you put log inside onBindViewHolder of RecylerView you find that all items loads at once in the start instead of based on the visibility of the item. This causes the parent LinearLayout (inside the ScrollView) to throw exception. I had also issue related to same with Recyclerview inside NestedScrollView.

Issue cause related  to above discussion:
If UI load more than 1-1.5 screens of content at a time.
Means you are loading unncessasary content which are not visible to user at a time on mobile screen. (While vertical RecyclerView inside NestedScrollView loads all its items at once in starting, instead of based on Recyclerview Visibility)

In the below answer @ivan V found issue related to the same and also given suggestions.
https://stackoverflow.com/questions/26664922/crash-material-design-android-5-0/27906489#answer-32966150

If you have crashlytics log for this issue then you can rectify the android Device and Android OS for which this type of Crashnalytics log detected.

Ho to detect issue:
1. Find all such activities whcih contains layout with LinearLayout.
2. Run you application and search your log and open each of your activity. Try to find during which activity log similar to below is detected.
W/OpenGLRenderer(18137): Layer exceeds max. dimensions supported by the GPU (1080x4628, max=4096x4096)
E/AndroidRuntime(18137): java.lang.IllegalStateException: Unable to create layer for  RelativeLayout
OR
Unable to create layer for v
OR
Fatal Exception: java.lang.IllegalStateException: Unable to create layer for LinearLayout, size 1080x4160 exceeds max size 4096
Reference: https://stackoverflow.com/questions/26626344/scene-transition-with-hero-elements-throws-layer-exceeds-max-dimensions-support#answer-27995911
Reference 2: https://stackoverflow.com/questions/26664922/crash-material-design-android-5-0/27906489#answer-27906489

Reference 3: Scene transition with hero elements throws Layer exceeds max. dimensions supported by the GPU

Solution :
Paginate your content and load no more than 1-1.5 screens of content at a time.

This will significantly decrease the screen size that is being pre-rendered during shared elements transition (it's being pre-rendered every time so the system knows where to place your transition object after transition)

Best Reference for solution:  https://stackoverflow.com/questions/26664922/crash-material-design-android-5-0/27906489#answer-32966150

I had the same issue & How I solved it:

My Layout was like below mentioned:
I have refactored my code such that there is only one main recycler view and all other layout are child of it. Using the RecycleView with multiple types of child views

Here I have replaced the logic part and UI part of Nested Scroll View items to different type of Recycler View holders inside Main RecyclerView.

You can see in bottom table I have replaced the Nested Scroll View and Linear-layout with a New Main RecyclerView.


BeforeAfter Refactoring from Scroll View to Recycler View
Nested Scroll View Main layout-> RecyclerView
LinearLayout
Horizontal Recycler View Child item layout-> Horizontal Recycler View
Two text View with two Horizontal Recycler Views Child item layout-> Two text View with two Horizontal Recycler Views
ImageView Child item layout-> ImageView
Horizontal Recuycler View Child item layout-> Horizontal Recycler View
Vertical Recuycler View (with 12 items of sametype) Child item layout-> With 12 items with same type as a childs of Main RecyclerView


Feel free to comment and post your solutions and doubts. 

Realm access from incorrect thread. Realm objects can only be accessed on the thread they were created

04-18 10:56:13.329 9961-10237/quizcounter.geeks.compete.myapplication E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #6
    Process: quizcounter.geeks.compete.myapplication, PID: 9961
    java.lang.RuntimeException: An error occurred while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:309)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
        at java.util.concurrent.FutureTask.run(FutureTask.java:242)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
        at java.lang.Thread.run(Thread.java:818)
     Caused by: java.lang.IllegalStateException: Realm access from incorrect thread. Realm objects can only be accessed on the thread they were created.
        at io.realm.BaseRealm.checkIfValid(BaseRealm.java:442)
        at io.realm.quizcounter_geeks_compete_myapplication_RealmUtils_PaperRealmProxy.realmGet$paperData(quizcounter_geeks_compete_myapplication_RealmUtils_PaperRealmProxy.java:120)
        at quizcounter.geeks.compete.myapplication.SplashScreenActivity$setQuestionsWithJsoup.doInBackground(SplashScreenActivity.java:562)
        at quizcounter.geeks.compete.myapplication.SplashScreenActivity$setQuestionsWithJsoup.doInBackground(SplashScreenActivity.java:556)
        at android.os.AsyncTask$2.call(AsyncTask.java:295)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
        at java.lang.Thread.run(Thread.java:818)

Async query cannot be created on current thread. Realm cannot be automatically updated on a thread without a looper

    --------- beginning of crash
04-17 17:31:36.081 32449-32733/quizcounter.geeks.compete.myapplication E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2
    Process: quizcounter.geeks.compete.myapplication, PID: 32449
    java.lang.RuntimeException: An error occurred while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:309)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
        at java.util.concurrent.FutureTask.run(FutureTask.java:242)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
        at java.lang.Thread.run(Thread.java:818)
     Caused by: java.lang.IllegalStateException: Async query cannot be created on current thread. Realm cannot be automatically updated on a thread without a looper.
        at io.realm.internal.android.AndroidCapabilities.checkCanDeliverNotification(AndroidCapabilities.java:54)
        at io.realm.RealmQuery.findAllAsync(RealmQuery.java:1811)
        at quizcounter.geeks.compete.myapplication.SplashScreenActivity$checkNotifIDsData.doInBackground(SplashScreenActivity.java:302)
        at quizcounter.geeks.compete.myapplication.SplashScreenActivity$checkNotifIDsData.doInBackground(SplashScreenActivity.java:280)
        at android.os.AsyncTask$2.call(AsyncTask.java:295)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
        at java.lang.Thread.run(Thread.java:818)
 
 
    --------- beginning of system

This Activity already has an action bar supplied by the window decor

02-11 12:20:19.602 30092-30092/com.elitech.offers.coupons.deals E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.elitech.offers.coupons.deals, PID: 30092
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.elitech.offers.coupons.deals/com.elitech.offers.coupons.deals.NetWork.NetworkConstatnt.NoInternetConnectionActivity_RestartApp}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2429)
        at android.app.ActivityThread.access$800(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:5333)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
        at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
        at android.support.v7.app.AppCompatDelegateImpl.setSupportActionBar(AppCompatDelegateImpl.java:345)
        at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:130)
        at com.elitech.offers.coupons.deals.NetWork.NetworkConstatnt.NoInternetConnectionActivity_RestartApp.onCreate(NoInternetConnectionActivity_RestartApp.java:41)
        at android.app.Activity.performCreate(Activity.java:5343)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2331)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2429)
        at android.app.ActivityThread.access$800(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:5333)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
        at dalvik.system.NativeStart.main(Native Method)


        <style name="AppTheme" parent="Theme.AppCompat.Light">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/header</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/header</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
        <item name="actionBarStyle">@style/MyActionBar</item>
        <item name="android:itemTextAppearance">@style/MyActionBar.MenuTextStyle</item>
        <item name="android:windowDisablePreview">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:itemBackground">@color/header</item>
        <item name="android:textColorSecondary">@color/white</item>
    </style>

Android: java.lang.IllegalStateException: This YouTubePlayer has been released

Process: com.daily.buzz, PID: 27644
    java.lang.IllegalStateException: This YouTubePlayer has been released
        at lmi.a(SourceFile:104)
        at lmi.a(SourceFile:181)
        at amrc.dispatchTransaction(SourceFile:162)
        at dbb.onTransact(SourceFile:7)
        at android.os.Binder.transact(Binder.java:387)
        at com.google.android.youtube.player.internal.d$a$a.a(Unknown Source)
        at com.google.android.youtube.player.internal.s.cueVideo(Unknown Source)
        at com.google.android.youtube.player.internal.s.cueVideo(Unknown Source)
        at com.daily.buzz.Search.SearchResultActivity.onClickedVideo(SearchResultActivity.java:170)
        at com.daily.buzz.Search.SearchTabItemsFragment.onVideoItemViewClick(SearchTabItemsFragment.java:215)
        at com.daily.buzz.Search.SearchResultRecyclerViewAdapter$1.onClick(SearchResultRecyclerViewAdapter.java:153)
        at android.view.View.performClick(View.java:5215)
        at android.view.View$PerformClick.run(View.java:21196)
        at android.os.Handler.handleCallback(Handler.java:742)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:157)
        at android.app.ActivityThread.main(ActivityThread.java:5603)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)

Fatal Exception: java.lang.IllegalStateException: Failure saving state: active fragment was removed from the FragmentManager

ANDROID STUDIO ERROR LOG:
E/FragmentManager: Failure saving state: active AllStoresFragmentListV2{fd50037 (4a8b618e-a0a8-45d0-aa37-ba08393b8f68) id=0x7f08009c} was removed from the FragmentManager
01-09 11:34:42.768 19169-19169/com.android.app E/FragmentManager: Activity state:
01-09 11:34:42.805 4746-6075/? E/ExecutionCriteria: Package unavailable for task: com.google.android.apps.fitness/.api.services.summary.ActivitySummaryGcmTaskService{u=0 tag="ActivitySummaryGcmTaskService" trigger=window{period=1800s,flex=180s,earliest=-27143018s,latest=-27142838s} requirements=[NET_ANY] attributes=[PERSISTED,RECURRING] scheduled=-27144638s last_run=N/A jid=N/A status=PENDING retries=0 client_lib=MANCHEGO_GCM-10400000}
01-09 11:34:42.880 19169-19169/com.android.app E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.android.app, PID: 19169
    java.lang.IllegalStateException: Failure saving state: active AllStoresFragmentListV2{fd50037 (4a8b618e-a0a8-45d0-aa37-ba08393b8f68) id=0x7f08009c} was removed from the FragmentManager
        at androidx.fragment.app.FragmentManagerImpl.saveAllState(FragmentManagerImpl.java:2315)
        at androidx.fragment.app.FragmentController.saveAllState(FragmentController.java:150)
        at androidx.fragment.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:496)
        at androidx.appcompat.app.AppCompatActivity.onSaveInstanceState(AppCompatActivity.java:511)
        at android.app.Activity.performSaveInstanceState(Activity.java:1348)
        at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1290)
        at android.app.ActivityThread.callCallActivityOnSaveInstanceState(ActivityThread.java:4202)
        at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3592)
        at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3658)
        at android.app.ActivityThread.access$1400(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1429)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:157)
        at android.app.ActivityThread.main(ActivityThread.java:5603)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)

Here, App using the latest gradle as below implementation 'androidx.core:core:1.1.0-alpha03'
I have compared crashing fragment with other fragment code and found the difference as below: Crashing fragment has method setRetainInstance(true); inside onCreateView() as shown in below snippet.
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
 setRetainInstance(true);
}
I come across the link which says not to use setRetainInstance : setRetainInstance - This can only be used with fragments not in the back stack I removed the setRetainInstance(true) for crashing fragmnet; It's working now.

HOW TO REPLICATE THIS ISSUE:
MainActivity --> HomeFragment --> FirstFragment(crashing fragment) --> HomeFragment
MainActivity loads with HomeFragment which replaced by FirstFragment and then going back to HomeFragment. Then moving my app to background and crash happens with below exception.
 java.lang.IllegalStateException: Failure saving state: active FirstFragment{fd50037 (4a8b618e-a0a8-45d0-aa37-ba08393b8f68) id=0x7f08009c} was removed from the FragmentManager

Read More about setRetainInstance(true)

Popular Posts