Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "array type expected found java.util.arraylist"?

Tags:

java

android

Given the function as below, AndroidStudio gives an error in the labeled line:

array type expected found java.util.arraylist

I also tried to use get instead of a direct referencing, but then Android Studio is telling me something that setItems cannot be resolved. The code is here:

protected void multiSelect(final ArrayList items) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    builder.setTitle("Selection")
            .setItems(items, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    Log.i("Select", "Selected entry: " + items[item]); // error here
                }
            });

    builder.create();
}
like image 643
Alex Avatar asked Nov 11 '15 19:11

Alex


1 Answers

Change

Log.i("Select", "Selected entry: " + items[item]);

to :

Log.i("Select", "Selected entry: " + items.get(item));

and change

protected void multiSelect(final ArrayList items)

to

protected void multiSelect(final ArrayList<String> items)

UPDATE:

the setItems method of the DialogBuilder expects an array, not an arrayList.

like image 73
Mohammed Aouf Zouag Avatar answered Nov 14 '22 01:11

Mohammed Aouf Zouag