I want to execute a search command this way but indicate error, any other way to modify this
```public class UserActivity extends AppCompatActivity {
private ImageView im;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.userpage);
im = (ImageView) findViewById(R.id.search);
im.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SearchTask();
}
});
static class SearchTask extends AsyncTask<Void, Void, Void>{
//TO DO
}
}```
Unfortunately the static class always indicates an error that is:Method call expected
2
Answers
SearchTask is a class and you need to instantiate it before use.
Replace
with
PS: pay attention that AsyncTask are deprecated in newer Android 11+ (The AsyncTask API is deprecated in Android 11. What are the alternatives?)
Your AsyncTask Implementation is wrong
Example Snippet from SO answer
Then use
new DownloadFilesTask().execute(url1, url2, url3);
Change your code like so