SDK 25.1.1 NPE: Attempt to invoke virtual method 'int android.view.View.getVisibility()' on a null object reference -


my code below, fragment popbackstackimmediate when fragmentempty resurface. works in support sdk 25.1.0 , before.

class fragmentempty : fragment() {      var fragmenttwo : fragment? = null     var fragmentone : fragment? = null      override fun oncreateview(inflater: layoutinflater, container: viewgroup?, savedinstancestate: bundle?): view? {         return inflater.inflate(r.layout.fragment_empty, container, false)     }       override fun onviewcreated(view: view?, savedinstancestate: bundle?) {         super.onviewcreated(view, savedinstancestate)          if (childfragmentmanager.findfragmentbytag("fragmentone") == null) {             fragmentone = fragmentone()             childfragmentmanager.begintransaction().add(r.id.container, fragmentone, "fragmentone").commit()         } else {             fragmentone = childfragmentmanager.findfragmentbytag("fragmentone")         }          if (childfragmentmanager.findfragmentbytag("fragmenttwo") != null) {             fragmenttwo = childfragmentmanager.findfragmentbytag("fragmenttwo")             childfragmentmanager.popbackstackimmediate()         } else {             fragmenttwo = fragmenttwo()         }          val transitioninflater = transitioninflater.from(activity)         val sharedelement = transitioninflater.inflatetransition(r.transition.shared_transition)         fragmenttwo?.sharedelementreturntransition = sharedelement         fragmentone?.sharedelemententertransition = sharedelement     }      fun openfragmenttwo() {         var fragmenttransaction = childfragmentmanager.begintransaction()         fragmenttransaction = fragmenttransaction.addsharedelement(activity.findviewbyid(r.id.fragment_button), "my_transition")         fragmenttransaction.replace(r.id.container, fragmenttwo, "fragmenttwo").addtobackstack("").commit()     }  } 

when move 25.1.1 , later e.g. 25.2.0. , 25.3.0, have error when popbackstackimmediate

 java.lang.nullpointerexception: attempt invoke virtual method 'int android.view.view.getvisibility()' on null object reference      @ android.support.v4.app.fragmenttransitioncompat21.findnamedviews(fragmenttransitioncompat21.java:387)      @ android.support.v4.app.fragmenttransition.captureoutsharedelements(fragmenttransition.java:693)      @ android.support.v4.app.fragmenttransition.configuresharedelementsunoptimized(fragmenttransition.java:605)      @ android.support.v4.app.fragmenttransition.configuretransitionsunoptimized(fragmenttransition.java:300)      @ android.support.v4.app.fragmenttransition.starttransitions(fragmenttransition.java:113)      @ android.support.v4.app.fragmentmanagerimpl.executeopstogether(fragmentmanager.java:2146)      @ android.support.v4.app.fragmentmanagerimpl.optimizeandexecuteops(fragmentmanager.java:2103)      @ android.support.v4.app.fragmentmanagerimpl.popbackstackimmediate(fragmentmanager.java:823)      @ android.support.v4.app.fragmentmanagerimpl.popbackstackimmediate(fragmentmanager.java:776)      @ myproject.com.myapplication.fragmentempty.onviewcreated(fragmentempty.kt:32)      @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1314)      @ android.support.v4.app.fragmentmanagerimpl.movefragmenttoexpectedstate(fragmentmanager.java:1528)      @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1595)      @ android.support.v4.app.backstackrecord.executepopops(backstackrecord.java:807)      @ android.support.v4.app.fragmentmanagerimpl.executeops(fragmentmanager.java:2360)      @ android.support.v4.app.fragmentmanagerimpl.executeopstogether(fragmentmanager.java:2149)      @ android.support.v4.app.fragmentmanagerimpl.optimizeandexecuteops(fragmentmanager.java:2103)      @ android.support.v4.app.fragmentmanagerimpl.popbackstackimmediate(fragmentmanager.java:823)      @ android.support.v4.app.fragmentmanagerimpl.popbackstackimmediate(fragmentmanager.java:776)      @ android.support.v4.app.fragmentactivity.onbackpressed(fragmentactivity.java:178)  

there's link stating fix https://code.google.com/p/android/issues/detail?id=234324&sort=-id&colspec=id%20type%20status%20owner%20summary%20sta

however hasn't been fix. wonder if there's workaround issue, while waiting fix, other stay in 25.1.0?

after research fragment of pre 25.1.0 , post 25.1.0, main different cause flow different setting default allowoptimization turn true false.

to 25.1.0 behavior when using later version of sdk, 1 set setallowoptimization(true) on fragmenttransaction.

    fun openfragmenttwo() {         var fragmenttransaction = childfragmentmanager.begintransaction()         fragmenttransaction = fragmenttransaction.setallowoptimization(true).addsharedelement(activity.findviewbyid(r.id.fragment_button), "my_transition")         fragmenttransaction.replace(r.id.container, fragmenttwo, "fragmenttwo").addtobackstack("").commit()     } 

this solve crash.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -