public void showToast(View view) {
Toast toast = new Toast.makeText(this, R.string.toast_message, Toast.LENGTH_SHORT);
toast.show();
}
error: cannot find symbol
Toast toast = new Toast.makeText(this, R.string.toast_message, Toast.LENGTH_SHORT);
^
symbol: class makeText
location: class Toast
As far as I can tell everything looks right, but for some reason I still keep getting this error.
CodePudding user response:
The problem is new Toast.makeText(..)
. This is a constructor invocation for a class makeText
nested in Toast
, such a class does not exist. You need to call the method makeText
of Toast
:
Toast toast = Toast.makeText(this, R.string.toast_message, Toast.LENGTH_SHORT);
CodePudding user response:
Toast.makeText
is a method, not a class. Remove the new
to call the method rather than trying to instantiate a class.
CodePudding user response:
Here Toast is an class, or makeText is an method which already exist in Toast
You need to write only Toast.makeText(CONTEXT, "YOUR_MESSAGE", Toast.LENGTH_SHORT).show();
instead of Toast toast = new Toast.makeText(...);
for more information you must be visit CLICK_HERE