Android Toast Error Activity Context.this cannot be resolved to a variable

Source: Internet
Author: User

Android development, I inserted a button in my activity, if andriod market can not find the words to use Toast to prompt, in the use of the time there are some problems, the following code error is the Context cannot be Resolved to a variable

1234567 uri Uri = Uri.parse (" market://details?id= "+ getapplicationcontext (). Getpackagename ()); intent gotomarket = new intent (Intent.action_view, URI); try {     startactivity (gotomarket); } catch (activitynotfoundexception e) {     toast.maketext (Activity. this , " couldn ' t launch the market "}

I tried the following call

Toast.maketext (This, "couldn t launch the market", Toast.length_long). Show ();
Then the developer tool hints the method Maketext (Context, charsequence, int) in the type Toast was not applicable for the arguments (new VIEW.O Nclicklistener () {}, String, int)

I used to use it, and I don't know how it's going to work.

Processing methods

After you have inherited the activity, use the following 2 ways
Toast.maketext (Classname.this, "couldn ' t launch the Market", Toast.length_long). Show ();
Or
Toast.maketext (Getapplicationcontext (), "couldn ' t launch the Market", Toast.length_long). Show ();

If your class inherits Fragment, use the following method
Toast.maketext (Getactivity (), "couldn ' t launch market", Toast.length_long). Show ();


Original address: http://www.itmmd.com/201411/153.html
This article by Meng Meng's IT person to organize the release, reprint must indicate the source.

Android Toast Error Activity Context.this cannot be resolved to a variable

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.