facing problem to show the message in toast
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 se开发者_开发技巧t the message in this toast
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
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();
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();
精彩评论