Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未选中从对象到Java 7的强制转换_Java_Eclipse_List_Java 7 - Fatal编程技术网

未选中从对象到Java 7的强制转换

未选中从对象到Java 7的强制转换,java,eclipse,list,java-7,Java,Eclipse,List,Java 7,我现在不知道Java不明白错误在哪里。使用Java7 public void chatMessage(String userName, String message) { IScope scope = Red5.getConnectionLocal().getScope(); ISharedObject chat = getSharedObject(scope, "chat"); List<ChatHistoryItem> history = (L

我现在不知道Java不明白错误在哪里。使用Java7

public void chatMessage(String userName, String message) {
      IScope scope = Red5.getConnectionLocal().getScope();
      ISharedObject chat = getSharedObject(scope, "chat");
      List<ChatHistoryItem> history = (List<ChatHistoryItem>) chat.getAttribute("remoteHistory");
      ChatHistoryItem item = new ChatHistoryItem();
      item.user = userName;
      item.date = new Date();
      item.message = message;
      history.add(item);
      chat.setAttribute("remoteHistory", history);
    }
public void聊天室消息(字符串用户名,字符串消息){
IScope scope=Red5.getConnectionLocal().getScope();
ISharedObject chat=getSharedObject(范围,“chat”);
List history=(List)chat.getAttribute(“remoteHistory”);
ChatHistoryItem项=新建ChatHistoryItem();
item.user=用户名;
item.date=新日期();
item.message=消息;
历史。添加(项目);
setAttribute(“远程历史记录”,历史记录);
}

错误:
未选中从对象到列表的强制转换

此问题是因为您无法安全地确定将由
IsSharedObject.getAttribute方法调用返回的类型。发生在这一行:

List<ChatHistoryItem> history = (List<ChatHistoryItem>) chat.getAttribute("remoteHistory");
List history=(List)chat.getAttribute(“remoteHistory”);
如果此方法返回的
对象
不是
List
类型,您将收到
ClassCastException
。如果该方法返回适当的类型,代码仍将执行

我假设这不是一个破坏代码的错误,它只是一个来自IDE的警告