如何修复“预期找到的数组类型 java.util.arraylist”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33658225/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fix "array type expected found java.util.arraylist"?
提问by Alex
Given the function as below, AndroidStudio gives an error in the labeled line:
给定如下函数,AndroidStudio 在标记行中给出错误:
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:
我也尝试使用get
而不是直接引用,但是 Android Studio 告诉我一些setItems
无法解决的问题。代码在这里:
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();
}
采纳答案by Mohammed Aouf Zouag
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
.
的setItems
方法DialogBuilder
需要一个array
,而不是一个arrayList
。