1

I'm trying to put an arraylist method into an arrayadapter but i am unable to do so. I am getting The constructor ArrayAdapter<String>(new Runnable(){}, int, ArrayList<RetrieveInternet>) is undefined

ArrayAdapter

            ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getPackages());

Arraylist method:

private ArrayList<RetrieveInternet> getPackages() {
    ArrayList<RetrieveInternet> apps = getPermissions(true); /* false = no system packages */
    final int max = apps.size();
    for (int i=0; i<max; i++) {
        apps.get(i);
        Log.e("TAG", apps.get(i).toString());
    }
    return apps;
}
1
  • 2
    The method parameter <RetrieveInternet> does not match the declared parameter <string>. These must match. Commented Jul 30, 2012 at 17:03

2 Answers 2

2

First parameter of ArrayAdapter constructor should be Context not Runnable. You are probably setting your adapter from within some Runnable so you cannot use this reference because it pointing at that Runnable instance. You should change this line:

ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getPackages());

into this:

ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(YourActivity.this, android.R.layout.simple_list_item_1, getPackages());

The main difference is first parameter - YourActivity.this which is reference to your activity in which you are setting your adapter.

Sign up to request clarification or add additional context in comments.

Comments

0

Obviously you are creating your adapter in a Runnable (in run() method), that's why this refers to the Runnable, not to a Context. Try to use YourActivity.this instead of this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.