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);
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With