我无法将元素添加到列表中?不支持的操作异常 [英] I am unable to add an element to a list? UnsupportedOperationException

查看:20
本文介绍了我无法将元素添加到列表中?不支持的操作异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个列表对象正在咬我的屁股..

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(","));

有什么想法吗?在 Google 上找不到任何有价值的东西.

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(",")));

这篇关于我无法将元素添加到列表中?不支持的操作异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆