Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/357.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 从hashmap检索实例化的对象_Java_Arraylist_Hashmap - Fatal编程技术网

Java 从hashmap检索实例化的对象

Java 从hashmap检索实例化的对象,java,arraylist,hashmap,Java,Arraylist,Hashmap,我真的不想问,但我已经走到了死胡同。我试图将hashmap中存储的对象数组构建为单个数组。我正在构建一个minecraft插件,我需要能够做到这一点,以便将所有玩家重置为其自然状态。然而,无论出于何种原因,我似乎无法将旁观者[]数组解析为单独的片段 目标只是允许一人以上进行检查。这是我的密码: public class EagleEye extends JavaPlugin implements Listener{ public HashMap<Spectatee, Spectator[

我真的不想问,但我已经走到了死胡同。我试图将hashmap中存储的对象数组构建为单个数组。我正在构建一个minecraft插件,我需要能够做到这一点,以便将所有玩家重置为其自然状态。然而,无论出于何种原因,我似乎无法将旁观者[]数组解析为单独的片段

目标只是允许一人以上进行检查。这是我的密码:

public class EagleEye extends JavaPlugin implements Listener{

public HashMap<Spectatee, Spectator[]> spec = new HashMap(Spectatee, Spectator[]);
public HashMap<Spectatee, Spectator[]> orinven = new HashMap<Spectatee, Spectator[]>;
public HashMap<Spectatee, Spectator[]> eeinven = new HashMap<Spectatee, Spectator[]>;

@Override
public void onEnable()
{
    //TODO:Who knows.
}
@Override
public void onDisable()
{
    //TODO:Spec off any players being spectated and spectating.

    Spectator[] frickinhell = spec.get(key)); 
    //Creates a master list of all spectators by uuid
    for(Spectator spec : spec.get(Spectator.class))
    {
        master.add(spec);
    }
    for(Object spec : master.toArray())
    {
        //Verify the player is online
        if(Bukkit.getPlayer(master)
            {
            //Verify the player is still spectating
            if(tators.get(uuid) == true)
            {
                //Stop spectating
                tators.put(uuid, false);
            }

        }

    }

}
公共类EagleEye扩展JavaPlugin实现监听器{
public HashMap spec=新的HashMap(Spectatee,旁观者[]);
public HashMap orinven=新HashMap;
public HashMap eeinven=新HashMap;
@凌驾
public void onEnable()
{
//托多:谁知道呢。
}
@凌驾
公共无效不可撤销()
{
//待办事项:对所有被监视和监视的玩家进行监视。
观众[]frickinhell=规格获取(关键点));
//按uuid创建所有观众的主列表
用于(观众规格:规格获取(观众等级))
{
主添加(规范);
}
对于(对象规范:master.toArray())
{
//验证播放机是否联机
if(Bukkit.getPlayer(master)
{
//验证玩家是否仍在观看
if(tators.get(uuid)=true)
{
//别看了
tators.put(uuid,false);
}
}
}
}
我知道这段代码的大部分都被破坏了。但是,我主要关心的是获取hashmap中存储的旁观者[]的所有实例中存储的旁观者[],并将其值重置为默认值。一旦我可以访问每个对象本身的每个实例,我就可以使用setter重置它们各自的值

干杯。

spec.get(consignator.class)
中,
consignator.class
与密钥类型不匹配,即
Spectatee
。因此,它返回null

如果希望有机会获得非空值,则应将
Spectatee
的实例传递给
spec.get()

如果您想收集所有观众,而不考虑他们的关键点,您可以迭代地图的值:

for (Spectator[] value : spec.values())
    for(Spectator spec : value)
    {
        master.add(spec);
    }

先生,你是一个奇迹工作者,如果我能投票给你,我会的。谢谢你的帮助。