Cannot resolve maketext() method of Toast

后端 未结 18 1628
南笙
南笙 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:37

    this in your case might not be the object of the activity. You might be using the Toast.makeText method inside you Click Listener object. To resolve this you need to use getApplicationContext() :

    Toast.makeText(getApplicationContext() , "Your Message", Toast.LENGTH_LONG);

提交回复
热议问题