zoukankan      html  css  js  c++  java
  • 我无法在列表中添加元素? UnsupportedOperationException异常(I am unable to add an element to a list? UnsupportedOperationException)

    转自:https://www.it1352.com/968919.html

    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?

    Actual declaration of variable:

    AdventureLobbies.players = Arrays.asList(rs.getString("players").toLowerCase().split(","));

    Any ideas? Can't find anything on Google that's worthwhile.

    解决方案

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

    这一个列表对象正在咬我... ...



    每当我尝试添加一个元素时,它就会产生这个:



     由以下原因引起:java.lang.UnsupportedOperationException 
    at java.util.AbstractList.add(AbstractList.java:148)
    at java.util.AbstractList.add(AbstractList.java:108)


    产生错误的行是无关紧要,但无论如何:



      AdventureLobbies.players.add(args [0] .toLowerCase()); 


    我是否应该静态访问它?



    < p>变量的实际声明:

    AdventureLobbies.players = Arrays.asList(rs.getString("players")。toLowerCase()。split (","));



    任何想法?在谷歌上找不到任何值得的东西。

  • 相关阅读:
    jstree 实现异步加载子节点
    创建 widget 窗口小组件
    Android(permission)常用权限
    Android 之 补间动画
    补间动画之 AlphaAnimation
    (转)向对象开发与面向组件开发的区别
    Android Drawable文件夹对应像素密度
    Notification(通知) 简单用法
    AlarmManager 用法
    关于IntentService 用法
  • 原文地址:https://www.cnblogs.com/sharpest/p/14951105.html
Copyright © 2011-2022 走看看