java.lang.UnsupportedOperationException at java.util.AbstractList.add(AbstractList.java:148) at java.util.AbstractList.add(AbstractList.java:108) at org.apache.commons.collections.CollectionUtils.addAll(CollectionUtils.java:688) at com.bosssoft.hr.train.j2se.util.UtilsDemo.method2(UtilsDemo.java:60) at Test1.testUtilsDemo2(Test1.java:56) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63) at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.ParentRunner.run(ParentRunner.java:413) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38) at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
时间: 2023-12-31 16:04:11 浏览: 40
这个异常是java.lang.UnsupportedOperationException,它表示不支持的操作。在你提供的堆栈跟踪中,该异常是在UtilsDemo的method2方法中抛出的。
根据堆栈跟踪,异常是在java.util.AbstractList.add方法中抛出的。在此方法中,添加元素的操作不受支持,因此抛出了UnsupportedOperationException异常。
要解决此问题,你需要检查method2方法中的代码,并确保在使用add方法添加元素之前,你正在操作支持添加操作的列表或集合。另外,还要确保你使用的集合实例已经实例化和初始化。
如果你能提供method2方法的代码,我可以帮助你更具体地解决这个问题。
相关问题
Caused by: java.lang.UnsupportedOperationException: null
引用\[1\]中的异常"java.lang.UnsupportedOperationException: null"是由于在使用Arrays.asList()方法将数组转换为列表时,生成的列表是Arrays的内部类ArrayList,而不是java.util.ArrayList。这两个ArrayList都继承自AbstractList,但是Arrays的内部类ArrayList没有重写AbstractList的add和remove方法,而是直接抛出了java.lang.UnsupportedOperationException异常。因此,当使用add或remove方法时,会导致该异常的抛出。\[2\]
另外,引用\[3\]中提到,如果在xml文件中的resultType类型定义错误,也会导致类似的异常。在这种情况下,需要确保resultType的类型与实际的实体类类型匹配,以避免出现java.lang.UnsupportedOperationException异常。\[3\]
#### 引用[.reference_title]
- *1* *2* [java.lang.UnsupportedOperationException: null异常处理](https://blog.csdn.net/qq_40236927/article/details/123198161)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [Caused by: java.lang.UnsupportedOperationException: null 解决办法](https://blog.csdn.net/qq_37950196/article/details/108627860)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
Cause: java.lang.UnsupportedOperationException
根据提供的引用内容,抛出异常"java.lang.UnsupportedOperationException"的原因是对不支持的操作进行了调用。这个异常通常在对不可变或只读的集合进行修改操作时抛出,比如使用了继承自`java.util.AbstractList`的`List`类的`remove`方法。引用中的异常栈显示了抛出异常的具体位置,其中`AbstractList.remove`和`AbstractList$Itr.remove`表示在`AbstractList`类和`AbstractList$Itr`类的`remove`方法中抛出了异常。这个异常也可以在使用`asList`方法继承的父类的`add`和`remove`方法时抛出,比如`java.util.ArrayList`类重写了父类的`add`和`remove`方法。引用提供了一个关于`asList`方法的解释,说明了为什么会抛出`UnsupportedOperationException`异常。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [java.lang.UnsupportedOperationException异常(csdn)————程序.pdf](https://download.csdn.net/download/qq_60706858/53598513)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [java.lang.UnsupportedOperationException 异常的解决方法及相关原因](https://blog.csdn.net/weixin_43228155/article/details/122866078)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [java.lang.UnsupportedOperationException的解决方法](https://blog.csdn.net/weixin_64738832/article/details/125085433)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)