我有一个最终的字符串列表(它必须是一个最终列表才能在 SetonClickListener 中使用它),当我想将项目添加到这个列表时,它会抛出一个“UnSoppurtedOperationException”
这是日志猫:
04-06 09:05:35.585: E/AndroidRuntime(1179): FATAL EXCEPTION: main
04-06 09:05:35.585: E/AndroidRuntime(1179): java.lang.UnsupportedOperationException
04-06 09:05:35.585: E/AndroidRuntime(1179): at java.util.AbstractList.add(AbstractList.java:404)
04-06 09:05:35.585: E/AndroidRuntime(1179): at java.util.AbstractList.add(AbstractList.java:425)
04-06 09:05:35.585: E/AndroidRuntime(1179): at com.example.sale.GroupActivity$MyCustomAdapter$1.onClick(GroupActivity.java:385)
04-06 09:05:35.585: E/AndroidRuntime(1179): at android.view.View.performClick(View.java:4204)
04-06 09:05:35.585: E/AndroidRuntime(1179): at android.view.View$PerformClick.run(View.java:17355)
04-06 09:05:35.585: E/AndroidRuntime(1179): at android.os.Handler.handleCallback(Handler.java:725)
04-06 09:05:35.585: E/AndroidRuntime(1179): at android.os.Handler.dispatchMessage(Handler.java:92)
04-06 09:05:35.585: E/AndroidRuntime(1179): at android.os.Looper.loop(Looper.java:137)
04-06 09:05:35.585: E/AndroidRuntime(1179): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-06 09:05:35.585: E/AndroidRuntime(1179): at java.lang.reflect.Method.invokeNative(Native Method)
04-06 09:05:35.585: E/AndroidRuntime(1179): at java.lang.reflect.Method.invoke(Method.java:511)
04-06 09:05:35.585: E/AndroidRuntime(1179): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-06 09:05:35.585: E/AndroidRuntime(1179): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-06 09:05:35.585: E/AndroidRuntime(1179): at dalvik.system.NativeStart.main(Native Method)
04-06 09:05:38.784: I/Process(1179): Sending signal. PID: 1179 SIG: 9
04-06 09:05:39.694: E/Trace(1425): error opening trace file: No such file or directory (2)
这是我的代码:
String name="a";
String freindsAccepted = groupFreindsAcceptedInside.get(position);
final List<String> accepted = Arrays.asList(freindsAccepted.split(","));
final String[] arrayAccepted = accepted.toArray(new String[accepted.size()]);
acceptBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Thread thread = new Thread()
{
@Override
public void run() {
//perform something
}
};
thread.start();
accepted.add(name);
String[] arrayAcceptedInside = accepted.toArray(new String[accepted.size()]);
if(accepted.size()>1) {
groupAccepted.setText("Accepted: "+accepted.get(0)+","+ accepted.get(1)+"...see More");
}
else {
groupAccepted.setText("Accepted: "+accepted.get(0));
}
}
});
其中第 385 行是:
accepted.add(name);
多谢