本文介绍了在ArrayList中,java.lang.UnsupportedOperationException删除项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want remove item in array list select location

我的code是

    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异常

but i got a Exception 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

如何在扣片这个问题..提前感谢名单花花公子

How to cleat this issue .. Advance thanx dude

推荐答案

修改

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

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

和看到这个帖子为什么会发生在名单的情况下,这个错误:

and see this post why this error occur in case of List :

Why试图从列表中删除时,我得到UnsupportedOperationException异常?

这篇关于在ArrayList中,java.lang.UnsupportedOperationException删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 11:28