0

Hello i am using this tutorial to set the spinwheel for my webview , its working perfectly after removing this line

Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show(); and the errot is on actitvity ,

plus i would like to know that if there is no internet connection how we can set the message in this toast

umar
  • 3,073
  • 5
  • 35
  • 45

3 Answers3

4

From the url example you have to write


//Main.java
Toast.makeText(Main.this, "Oh no! " + description, Toast.LENGTH_SHORT).show();
//this is also correct
Toast.makeText(getApplicationContext(), "Oh no! " + description, Toast.LENGTH_SHORT).show();

For internet connectivity checking

Community
  • 1
  • 1
hossaindoula
  • 980
  • 10
  • 21
3

That first parameter in makeText() should be a Context. I'm assuming what the author of the tutorial meant by activity was a non-static reference to the Activity class in which you're programming. You would correctly reference it with something like

//MyActivity.java

Toast.makeText(MyActivity.this, "Oh no!" + description, Toast.LENGTH_SHORT).show();
Glendon Trullinger
  • 4,052
  • 1
  • 28
  • 35
0
Toast.makeText(MyActivity.this, "Oh no!" + description, Toast.LENGTH_SHORT).show();

otherwise you can also use

Toast.makeText(getApplicationContext(), "Oh no!" + description, Toast.LENGTH_SHORT).show();
Aliaksei Kliuchnikau
  • 13,589
  • 4
  • 59
  • 72
Ronak Mehta
  • 5,971
  • 5
  • 42
  • 69