sephiroth74 / android-target-tooltip

Create Toast like tooltips, but targets can be specified, plus custom properties and features
MIT License
1.5k stars 278 forks source link

parent.windowToken must not be null #122

Open sembozdemir opened 5 years ago

sembozdemir commented 5 years ago

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?

kassim commented 5 years ago

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

Sulfkain commented 5 years ago

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

kassim commented 5 years ago

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

wifirevaithi commented 5 years ago

Hi, i have same issue please help me

wifirevaithi commented 5 years ago

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

can you explain it how can i do?

kassim commented 5 years ago

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

textView.post(()-> { showTooltip()})
Joze01 commented 1 year ago

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

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

shubham2011mnnit commented 11 months ago

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.