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 4119240
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:03:54+00:00 2026-05-20T23:03:54+00:00

package com.example.helloandroid; import java.io.File; import android.os.AsyncTask; import android.os.Environment; import android.widget.Toast; public class CheckTask extends

  • 0
package com.example.helloandroid;

import java.io.File;

import android.os.AsyncTask;
import android.os.Environment;
import android.widget.Toast;

public class CheckTask extends AsyncTask<Void, Void, Boolean> {



protected Boolean doInBackground(Void... params) {
    while (true) {
        if (Environment.MEDIA_MOUNTED.equals(Environment
                .getExternalStorageState())) {
            // access external file
            String f = Environment.getExternalStorageDirectory()
                    + "/schedule.rtf";
            File s = new File(f);
            if (s.exists()) {
                return true;

            }

        }
    }

}

protected void onPostExecute(Boolean result) {
    if (result == true) {


         Toast.makeText(CheckTask.this, "Hello", Toast.LENGTH_SHORT).show();

    }
}
}

I keep getting the following error message:
The method makeText(Context, CharSequence, int) in the type Toast is
not applicable for the arguments (CheckTask, String, int)

I have tried searching some basic tutorials and they use Toast.makeText in the same way as above. I am not sure whats wrong.

Thank you.

  • 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-20T23:03:55+00:00Added an answer on May 20, 2026 at 11:03 pm

    It’s because you are passing the CheckTask object instance in to makeText. You need to pass the instance/Context of your activity.

    Is your AsyncTask an inner class of an actual activity? That is how the example below works and how I have always seen it done when looking at other people’s code.

    Here’s a working example. Ignore the package name, I was having a play with creating a pedometer awhile back and just reused that project to do this.

    package jm.pedometer;
    
    import android.app.Activity;
    import android.graphics.Typeface;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.widget.Toast;
    
    public class MainView extends Activity {
        Chronometer mChronometer;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        mChronometer = (Chronometer)findViewById(R.id.Chronometer01);
        mChronometer.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/digital_clock.ttf"));
    
        CheckTask testTask = new CheckTask();
        testTask.execute();
    }
    
    
    /*
     * This AsyncTask is an inner class within an Activity
     */
    public class CheckTask extends AsyncTask<Void, Void, Boolean> {
    protected Boolean doInBackground(Void... params) {
        return true;
    }
    
    protected void onPostExecute(Boolean result) {
        if (result == true) {
        Toast.makeText(MainView.this, "Hello", Toast.LENGTH_SHORT).show();
        }
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

package com.example.helloandroid; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class HelloAndroid extends Activity {
package com.example.android.home; import android.app.Activity; import android.os.Bundle; import android.widget.*; import android.view.*; public class HomeActivity extends
package com.example.helloandroid; import android.app.Activity; import android.os.Bundle; import android.widget.Button; import android.view.View; import android.view.View.OnClickListener; //Create an
I am interested in using a class file (CameraPreview.java) from this package com.example.android.apis.graphics. I
package com.example.helloandroid; import java.util.ArrayList; import java.util.Arrays; import android.app.TabActivity; import android.os.Bundle; import android.view.Window; import android.widget.ArrayAdapter;
The code is also at https://github.com/timp21337/java-generics-example package a; import java.util.List; public interface Container<T> {
package com.example.Calc; import android.R.string; import android.app.ListActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter;
My directory structure is: ABC/src/com/example/model/a.java ABC/src/com/example/web/b.java Code for a.java : package com.example.model; public class
Main Activity Code. BroadcastExample.java package com.example.broadcast; import android.app.Activity; import android.os.Bundle; import android.util.Log; public class
Here is My Whole Code....... BroadcastExample.java package com.example.broadcast; > import android.app.Activity; import > android.content.Context;

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.