gpt4 book ai didi

android - 删除 arrayList 中的项目,java.lang.UnsupportedOperationException

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:46:45 25 4
gpt4 key购买 nike

我想删除数组列表选择位置中的项目

我的代码是

    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);
}

但是我得到了一个异常 UnsupportedOperationException

错误

    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));

并查看这篇文章为什么在 List 的情况下会出现此错误:

Why do I get an UnsupportedOperationException when trying to remove an element from a List?

关于android - 删除 arrayList 中的项目,java.lang.UnsupportedOperationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13965094/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com