android-target-tooltip icon indicating copy to clipboard operation
android-target-tooltip copied to clipboard

parent.windowToken must not be null

Open sembozdemir opened this issue 6 years ago • 8 comments

Hi,

I could not make it to show tooltip. It always crash by saying parent.windowToken must not be null

Stacktrace:

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.altayer.nisnass.betaDebug/com.altayer.nisnass.pdp.PdpActivity}: java.lang.IllegalStateException: parent.windowToken must not be null
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2781)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2859)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1592)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6518)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: java.lang.IllegalStateException: parent.windowToken must not be null
        at it.sephiroth.android.library.xtooltip.Tooltip.show(Tooltip.kt:623)
        at com.altayer.nisnass.pdp.ui.PdpFragment.onViewCreated(PdpFragment.kt:339)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1471)
        at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
        at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269)
        at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229)
        at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:201)
        at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:620)
        at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:178)

Code to show tooltip:

Tooltip.Builder(activity)
        .anchor(deliveryTypeView, 0, 0, false)
        .text(R.string.product_sla_preselected_info)
        .arrow(true)
        .overlay(true)
        .create()
        .show(deliveryTypeView, Tooltip.Gravity.TOP, true)

What is wrong with my implementation? Could you please help?

sembozdemir avatar Jan 28 '19 11:01 sembozdemir

I found the same issue. I fixed it by putting it in a view.post() call.

kassim avatar Jan 28 '19 17:01 kassim

I the workaroud of Kassim it works, seems that you set the tooltip too early on the lifecycle, when no all the views was loaded.

Be sure to use OnViewCreated on Fragment or use the work around @kassim told

Sulfkain avatar Feb 28 '19 15:02 Sulfkain

mine was in a ViewHolder of RecyclerView, which would have items added in onViewCreated maybe the 'show' method itself should be using post?

kassim avatar Feb 28 '19 18:02 kassim

Hi, i have same issue please help me

vaithitheone avatar Mar 23 '19 07:03 vaithitheone

I found the same issue. I fixed it by putting it in a view.post() call.

can you explain it how can i do?

vaithitheone avatar Mar 23 '19 07:03 vaithitheone

select any view in your layout, for example a TextView, has a post method you can call

textView.post(()-> { showTooltip()})

kassim avatar Mar 23 '19 07:03 kassim

I was having the issue inside a recycler view. this fixed it:

holder.itemView.post { holder.showTooltip() }

Joze01 avatar Sep 25 '23 08:09 Joze01

when i am clicking second time on same item of recylerview, the activity closes itself

FATAL EXCEPTION: main Process: com.Dominos, PID: 30862 java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

shubham2011mnnit avatar Oct 26 '23 07:10 shubham2011mnnit