我尝试在onNewIntent
方法的onPostexecute
方法中获取意图后,显示AlertBuild对话框。 routeList
有[1,9,13]。目前我收到此错误java.lang.ArrayStoreException: source[0] of type java.lang.Integer cannot be stored in destination array of type java.lang.CharSequence[]
ArrayList<Integer> routeList = extras
.getIntegerArrayList("stop_route"); //[1,9,13]
int routeListSize = routeList.size();
if(routeListSize > 0){
CharSequence charSequence[] = routeList
.toArray(new CharSequence[routeList.size()]);
for (int i = 0, size = routeList.size(); i < size; i++) {
charSequence[i] = String.valueOf(routeList.get(i));
}
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select");
builder.setMultiChoiceItems(charSequence, null,
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which,
boolean isChecked) {
// TODO Auto-generated method stub
}
});
}
答案 0 :(得分:6)
尝试像这样更改for
:
String[] charSequence = new String[routeList.size()];
for (int i = 0, i<routeList.size(); i++) {
charSequence[i] = String.valueOf(routeList.get(i));
}
而不是:
CharSequence charSequence[] = routeList
.toArray(new CharSequence[routeList.size()]);
for (int i = 0, size = routeList.size(); i < size; i++) {
charSequence[i] = String.valueOf(routeList.get(i));
}
答案 1 :(得分:0)
CharSequence
只能使用字符串值,但是您的routeList
类型是Integer
。因此,当您用数据填充charSequence[i]
时,需要将项目类型更改为String
。
错误:charSequence[i] = routeList.get(i);
右:charSequence[i] = routeList.get(i).toString();