Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve symbol 'execute' ... calling AsyncTask

I am trying to make a GET request on a URL, I created a class extending AsyncTask<Void, Void, Void> and I try to call new MyClass.execute() ... I have done this before and it worked, today it is not working. What am I doing wrong?

Here is my code:

public class SignUpActivity extends AppCompatActivity {

String TAG = SignUpActivity.class.getSimpleName();
String URL;

ArrayList<String> countries = new ArrayList<>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sign_up);

    new MyClass.execute();
}

private class MyClass extends AsyncTask<Void, Void, Void> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        //TODO
    }

    @Override
    protected Void doInBackground(Void... params) {
        HttpHandler sh = new HttpHandler();

        // Making a request to url and getting response
        String jsonStr = sh.makeServiceCall(URL, "GET");
        //Handling response in jsonStr code 
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        //TODO
    }

}
like image 621
Bugs Buggy Avatar asked Jun 04 '26 15:06

Bugs Buggy


1 Answers

This is a syntax error. It should be

new MyClass().execute();

not as new MyClass.execute();

like image 193
karthik vishnu kumar Avatar answered Jun 06 '26 03:06

karthik vishnu kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!