Cannot resolve maketext() method of Toast

后端 未结 18 2413
旧时难觅i
旧时难觅i 2021-02-07 02:02

I am getting error while creating a Toast

Toast toast = Toast.makeText(this, text, duration);

I am getting cannot resolve ma

18条回答
  •  礼貌的吻别
    2021-02-07 02:33

    The makeText's signature is the following

    public static Toast makeText (Context context, CharSequence text, int duration)
    

    the first paramter has to be a context object. You put this, but this refers to this object and it can be something different from an Activity (a Fragment for instance).

提交回复
热议问题