我要删除数组列表中的项选择位置
我的代码是

    List<String> historylist = Arrays.asList(history);
    if (historylist.size()>=3){
        System.out.print("*************************************************");
        Log.i(MyContants.StoredHistory_TAG,"StoredHistory size========="+ String.valueOf(historylist.size()));
        String removePosition=historylist.get(2);
        historylist.remove(removePosition);
    }

但我有一个异常不支持操作异常
错误
    12-20 09:16:27.680: I/StoredHistory Class(5715): StoredHistory size=========3
    12-20 09:16:27.680: D/AndroidRuntime(5715): Shutting down VM
    12-20 09:16:27.684: W/dalvikvm(5715): threadid=1: thread exiting with uncaught exception (group=0x4001d7d0)
    12-20 09:16:27.688: E/AndroidRuntime(5715): FATAL EXCEPTION: main
    12-20 09:16:27.688: E/AndroidRuntime(5715): java.lang.RuntimeException: Unable to start activity ComponentInfo{****PACKAGE NAME*****}: java.lang.UnsupportedOperationException
    12-20 09:16:27.688: E/AndroidRuntime(5715):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
    12-20 09:16:27.688: E/AndroidRuntime(5715):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
    12-20 09:16:27.688: E/AndroidRuntime(5715):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
    12-20 09:16:27.688: E/AndroidRuntime(5715):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
    12-20 09:16:27.688: E/AndroidRuntime(5715):     at android.os.Handler.dispatchMessage(Handler.java:99)
    12-20 09:16:27.688: E/AndroidRuntime(5715):     at android.os.Looper.loop(Looper.java:123)
    12-20 09:16:27.688: E/AndroidRuntime(5715):     at android.app.ActivityThread.main(ActivityThread.java:4627)
    12-20 09:16:27.688: E/AndroidRuntime(5715):     at java.lang.reflect.Method.invokeNative(Native Method)
    12-20 09:16:27.688: E/AndroidRuntime(5715):     at java.lang.reflect.Method.invoke(Method.java:521)
    12-20 09:16:27.688: E/AndroidRuntime(5715):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
    12-20 09:16:27.688: E/AndroidRuntime(5715):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    12-20 09:16:27.688: E/AndroidRuntime(5715):     at dalvik.system.NativeStart.main(Native Method)
    12-20 09:16:27.688: E/AndroidRuntime(5715): Caused by: java.lang.UnsupportedOperationException
    12-20 09:16:27.688: E/AndroidRuntime(5715):     at java.util.AbstractList.remove(AbstractList.java:645)
    12-20 09:16:27.688: E/AndroidRuntime(5715):     at java.util.AbstractList$SimpleListIterator.remove(AbstractList.java:77)
    12-20 09:16:27.688: E/AndroidRuntime(5715):     at java.util.AbstractCollection.remove(AbstractCollection.java:230)
    12-20 09:16:27.688: E/AndroidRuntime(5715):     at ******.utills.StoredHistory.storedHistorylist(StoredHistory.java:24)
    12-20 09:16:27.688: E/AndroidRuntime(5715):     at *******.ScanResult.onCreate(ScanResult.java:53)
    12-20 09:16:27.688: E/AndroidRuntime(5715):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
    12-20 09:16:27.688: E/AndroidRuntime(5715):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
    12-20 09:16:27.688: E/AndroidRuntime(5715):     ... 11 more

如何解决这个问题..先走,伙计

最佳答案

变化

List<String> historylist = Arrays.asList(history);


 List<String> historylist = new LinkedList (Arrays.asList(history));

看看这篇文章,为什么在列表中会出现这个错误:
Why do I get an UnsupportedOperationException when trying to remove an element from a List?

08-06 11:53