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

问题描述

public boolean onOptionsItemSelected(MenuItem item){
int id = item.getItemId();

switch(id){
    case R.id.jaren_3de:
        updateKlassenList(klassen);
        break;
    case R.id.jaren_4de:
        updateKlassenList(klassen2);
        break;
    case R.id.jaren_5de:
        updateKlassenList(klassen3);
        break;
    case R.id.jaren_6de:
        updateKlassenList(klassen4);
        break;

    // case R.id.

}

return super.onOptionsItemSelected(item);
}

private void updateKlassenList(String[] data) {
    klassenList.clear();
    klassenList.addAll(Arrays.asList(data));

    // I assume "adapter" is the adapter of interest.
    adapter.notifyDataSetChanged();
}

我添加了方法:

private void updateKlassenList(String[] data) {
    klassenList.clear();
    klassenList.addAll(Arrays.asList(data));

    // I assume "adapter" is the adapter of interest.
    adapter.notifyDataSetChanged();
}

解决先前的问题(请参见如何更改Android Studio中onOptionsItemSelected内部的List< String>值?),但是现在我遇到了Java.Lang.UnsupportedOperationsException.我一直在查找它,似乎与过时的版本有关,但是我最近更新了所有内容.

to fix a previous problem (see How to change List<String> value inside onOptionsItemSelected in Android Studio?), but now I am getting a Java.Lang.UnsupportedOperationsException. I've been looking it up and it seems it has something to do with outdated versions, but I recently updated everything.

提前谢谢!

这是我得到的错误:

01-10 16:08:23.508 1457-1457/com.geesplit.lessenrooster E/AndroidRuntime: FATAL EXCEPTION: main
                                                                      Process: com.geesplit.lessenrooster, PID: 1457
                                                                      java.lang.UnsupportedOperationException
                                                                          at java.util.AbstractList.remove(AbstractList.java:638)
                                                                          at java.util.AbstractList$SimpleListIterator.remove(AbstractList.java:75)
                                                                          at java.util.AbstractList.removeRange(AbstractList.java:658)
                                                                          at java.util.AbstractList.clear(AbstractList.java:466)
                                                                          at com.geesplit.lessenrooster.MainActivity.updateKlassenList(MainActivity.java:112)
                                                                          at com.geesplit.lessenrooster.MainActivity.onOptionsItemSelected(MainActivity.java:95)
                                                                          at android.app.Activity.onMenuItemSelected(Activity.java:2885)
                                                                          at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1133)
                                                                          at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:761)
                                                                          at com.android.internal.view.menu.SubMenuBuilder.dispatchMenuItemSelected(SubMenuBuilder.java:81)
                                                                          at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
                                                                          at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:904)
                                                                          at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:894)
                                                                          at com.android.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:186)
                                                                          at android.widget.AdapterView.performItemClick(AdapterView.java:305)
                                                                          at android.widget.AbsListView.performItemClick(AbsListView.java:1146)
                                                                          at android.widget.AbsListView$PerformClick.run(AbsListView.java:3053)
                                                                          at android.widget.AbsListView.onTouchUp(AbsListView.java:3872)
                                                                          at android.widget.AbsListView.onTouchEvent(AbsListView.java:3637)
                                                                          at android.view.View.dispatchTouchEvent(View.java:8471)
                                                                          at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2399)
                                                                          at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2092)
                                                                          at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
                                                                          at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
                                                                          at android.widget.PopupWindow$PopupViewContainer.dispatchTouchEvent(PopupWindow.java:1731)
                                                                          at android.view.View.dispatchPointerEvent(View.java:8666)
                                                                          at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4123)
                                                                          at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3989)
                                                                          at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3544)
                                                                          at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3597)
                                                                          at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3563)
                                                                          at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3680)
                                                                          at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3571)
                                                                          at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3737)
                                                                          at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3544)
                                                                          at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3597)
                                                                          at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3563)
                                                                          at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3571)
                                                                          at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3544)
                                                                          at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5807)
                                                                          at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5781)
                                                                          at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5752)
                                                                          at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5897)
                                                                          at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
                                                                          at android.os.MessageQueue.nativePollOnce(Native Method)
                                                                          at android.os.MessageQueue.next(MessageQueue.java:143)
                                                                          at android.os.Looper.loop(Looper.java:122)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5257)
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at java.lang.reflect.Method.invoke(Method.java:372)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

推荐答案

由于此线程,我想通了:我现在使用的是LinkedList而不是普通的List,它可以正常工作!

I figured it out, thanks to this thread: Why do I get an UnsupportedOperationException when trying to remove an element from a List?I used a LinkedList instead of an ordinary List now, and it works!

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

08-24 11:28