Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4532680
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:03:38+00:00 2026-05-21T14:03:38+00:00

i have a method in my main activity which is of void return type.if

  • 0

i have a method in my main activity which is of void return type.if i create a Toast inside the method it shows the error “Type mismatch:cannot convert void to toast”. can anyone explain what is the problem and help me with solution ?

public class HelloList<View> extends ListActivity  {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));
 ListView lv=getListView();
      lv.setTextFilterEnabled(true);
      lv.setOnItemClickListener(new OnItemClickListener(){ 
            @Override

            public void onItemClick(AdapterView<?> arg0,android.view.View arg1, int arg2, long arg3) {
                // TODO Auto-generated method stub 
            //  Toast.makeText(getApplicationContext(), ((TextView) arg1).getText(),Toast.LENGTH_SHORT).show();
                System.out.println(arg2);
                String s="position is "+arg2;
                Toast.makeText(getApplicationContext(),s,Toast.LENGTH_SHORT).show();
            }

          });
      registerForContextMenu(lv);
      /*int i=lv.getCheckedItemPosition();
          Toast.makeText(getApplicationContext(),,Toast.LENGTH_SHORT).show();*/
    }
    public void onCreateContextMenu(ContextMenu menu, android.view.View v,
                                    ContextMenuInfo menuInfo) {
      super.onCreateContextMenu(menu, v, menuInfo);
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(0x7f030000, menu);
    }

    public boolean onContextItemSelected(MenuItem item) {
      AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
      switch (item.getItemId()) {
      case 0x7f030000:
        editNote(info.id);
        return true;

      default:
        return super.onContextItemSelected(item);
      }
    }

   public void editNote(long id) {
    Toast m=Toast.makeText(this, "asdasd", 3);
    m.show();

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T14:03:39+00:00Added an answer on May 21, 2026 at 2:03 pm

    The problem is that you can assign a method to a variable. A toast should look like this if you want to directly display it:

    Toast.makeText(context, text, duration).show();
    

    or in your case:

    Toast.makeText(this, "sadasd", 2).show();
    

    If you want to store the Toast in a variable and then display it, you have to do it like this:

    Toast toast = Toast.makeText(context, text, duration);
    
    toast.show();
    

    Or in your specific case:

    Toast toast = Toast.makeText(this, "sadasd", 2);
    toast.show();
    

    On a side note: It would be better to use the constants LENGHT_SHORT and LENGTH_LONG in Toast to define the duration instead of 2. Especially if 2 does not seem to be a valid value here. See here fore more details: http://developer.android.com/reference/android/widget/Toast.html

    Then it would look like this:

    Toast.makeText(this, "sadasd", Toast.LENGTH_LONG).show();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a main Activity called Main which has onActivityResult Method. protected void onActivityResult(int
I have this method inside an Activity which implements an ImageLoader class: public void
I have a method which takes params object[] such as: void Foo(params object[] items)
I'm writing an Android app. I have a main method, which creates and runs
I have a JSON file which is populated to an activity (Main.java). This Activity
For instance in C# or Java, you always have a main() method used to
I have a method that can return either a single object or a collection
I have a method in .NET (C#) which returns string[][] . When using RegAsm
I have a method which should be executed in an exclusive fashion. Basically, it's
I have the following problem. My main activity consists of a ListView populated with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.