Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The constructor ArrayAdapter<String>(int, ArrayList<String>) is undefined

Well the title says it all. I'm not sure why it doesn't want to work.

This is in an AsyncWorker so that might be the issue. Also the variables are outside of a protected method but the same happens when inside.

private class MyAsyncTask extends AsyncTask<String, String, String> {


    ListView workersList = (ListView)findViewById (R.id.workers_list);
    ArrayList<String> itemsList = new ArrayList<String>();


    protected String doInBackground(String... arg0) {

Then later on

ArrayAdapter<String> adapter = new ArrayAdapter<String>(android.R.layout.simple_list_item_1, itemsList);
like image 617
justauser Avatar asked Mar 15 '26 02:03

justauser


2 Answers

You forgot the context parameter. Change to:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(<ActivityName>.this, android.R.layout.simple_list_item_1, itemsList);

where replace <ActivityName> with the name of your activity class.

like image 64
Amulya Khare Avatar answered Mar 16 '26 16:03

Amulya Khare


Check out the documentation on ArrayAdapter. It doesn't have a constructor with parameters (int, ArrayList). If you prepend context as well then you'll have a constructor that exists.

ArrayAdapter<String> adapter = new ArrayAdapter<String>(<ActivityName>.this, android.R.layout.simple_list_item_1, itemsList);

More info: http://developer.android.com/reference/android/widget/ArrayAdapter.html

like image 21
Tyler Ferraro Avatar answered Mar 16 '26 15:03

Tyler Ferraro



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!