Search code examples
androidkotlintoastandroid-toastanko

Anko toast() method causes java.lang.NoSuchMethodError when called from Fragment


I'm having following error when I'm calling toast("Toast's message text") from Android Fragment:

java.lang.NoSuchMethodError: No virtual method getActivity()Landroid/app/Activity; in class Landroid/support/v4/app/Fragment; or its super classes (declaration of 'android.support.v4.app.Fragment' appears in name-of-the-file-classes.dex)

I'm using Anko v0.9.1 and Kotlin 1.0.6

What might be the cause of this crash? Standard Android Toast works just fine. Also toast() function works inside Activities.


Solution

  • It is very strange, probably it is a bug.

    But next works for me

    activity.toast("Toast's message text")
    

    or

    context.toast("Toast's message text")