我无法在列表中添加元素? UnsupportedOperationException异常 [英] I am unable to add an element to a list? UnsupportedOperationException
本文介绍了我无法在列表中添加元素? UnsupportedOperationException异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这一个列表对象正在咬我... ...
This one list object is biting me in the butt..
每当我尝试添加一个元素时,它就会产生这个:
Any time I try to add an element to it, it produces this:
Caused by: java.lang.UnsupportedOperationException
at java.util.AbstractList.add(AbstractList.java:148)
at java.util.AbstractList.add(AbstractList.java:108)
产生错误的行是无关紧要,但无论如何:
The line producing the error is insignificant, but here it is anyways:
AdventureLobbies.players.add(args[0].toLowerCase());
我是否应该静态访问它?
Should I not be accessing it statically?
变量的实际声明:
AdventureLobbies.players = Arrays.asList(rs.getString(players)。toLowerCase()。split (,));
任何想法?在谷歌上找不到任何值得的东西。
Any ideas? Can't find anything on Google that's worthwhile.
推荐答案
Arrays.asList()会给你一个不可修改的列表,那个这就是你的添加失败的原因。尝试使用以下命令创建列表:
Arrays.asList() will give you back an unmodifiable list, and that is why your add is failing. Try creating the list with:
AdventureLobbies.players = new ArrayList(Arrays.asList(rs.getString("players").toLowerCase().split(",")));
这篇关于我无法在列表中添加元素? UnsupportedOperationException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文