gpt4 book ai didi

java - list.add(element) 不支持的操作异常

转载 作者:行者123 更新时间:2023-12-01 18:33:06 26 4
gpt4 key购买 nike

info.add(("§eEntity Type: §f" + e.getType()));

该行抛出不支持的操作异常。 e是Entity类的一个对象,info是一个List,初始化如下:

List<String> info = new ArrayList<String>();

为什么会发生这种情况?

完整的堆栈跟踪为:http://pastebin.com/XC996QFS(我添加了文本来标识跟踪中最有趣的行)

我正在使用的 API 链接在源代码顶部的注释中。

完整源代码为:http://pastebin.com/VEQYGGrM

最佳答案

要发生这种情况,请执行以下任一操作:

info 实际上并不是一个 ArrayList,并且在某个时刻为其分配了不同的列表(例如 Collections.emptyListCollections.singletonListArrays.asList,将其包装在某种不可变列表中,等等)。

e.getType() 引发异常。

异常堆栈跟踪将帮助您确认属于哪种情况。

关于java - list.add(element) 不支持的操作异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23249372/

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