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();
}
一個java.lang.unsupportedoperationexception我添加的方法:我有Android Studio中
private void updateKlassenList(String[] data) {
klassenList.clear();
klassenList.addAll(Arrays.asList(data));
// I assume "adapter" is the adapter of interest.
adapter.notifyDataSetChanged();
}
來解決前一個問題(見How to change List<String> value inside onOptionsItemSelected in Android Studio?),但現在我得到一個java.lang中。 UnsupportedOperationsException。我一直在尋找它,似乎它與過時的版本有關,但我最近更新了一切。
提前致謝!
編輯:這是我得到的錯誤:
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)
請發佈整個堆棧跟蹤以及觸發堆棧跟蹤的Java代碼。 – CommonsWare
「List」的類型不支持刪除 - 您使用的是不可修改的列表嗎?記錄'klassenList'類併發布結果。 –