Type mismatch: cannot convert from element type Object to Map.Entry

Discussion in 'Spigot Plugin Development' started by Mattgamee, Jun 29, 2016.

  1. Hello, I am trying to fix the plugin BiomeSwitcher to make it work for 1.10.
    However there is this one error that I cannot figure out how to fix:
    Code (Text):
    Type mismatch: cannot convert from element type Object to Map.Entry
    Here is the code that is causing the problem:
    Code (Text):

     try {
         BiomeRegistry registry = new BiomeRegistry();
        RegistryMaterials<MinecraftKey, BiomeBase> oldRegistry = BiomeBase.REGISTRY_ID;
           RegistryID oldIDRegistry = (RegistryID)ReflectionUtils.getValue(RegistryMaterials.class, oldRegistry, "a");
      Map oldDataRegistry = (Map)ReflectionUtils.getValue(RegistryMaterials.class, oldRegistry, "b");

    for (Map.Entry entry : oldDataRegistry.entrySet()) {
    //"oldDataRegistry.entrySet())" is causing the problem
           int id = oldIDRegistry.getId((BiomeBase)entry.getKey());
            if ((id != -1) && (entry.getKey() != null))
           {
         registry.register(id, (MinecraftKey)entry.getValue(), (BiomeBase)entry.getKey());     }
    Please note that I am a beginner, I do not even understand this code but I am just trying to help the community (and use the plugin).
    Cheers
     
    #1 Mattgamee, Jun 29, 2016
    Last edited: Jun 29, 2016
  2. Can you post where the 'oldDataRegistry' map is located and the code for it please?
     
  3. It is there?
     
  4. Maybe on
    Code (Text):
     Map oldDataRegistry = (Map)ReflectionUtils.getValue(RegistryMaterials.class, oldRegistry, "b");
    Parameterize the data if you can. So (Map<DataType1, DataType2>) as the cast, and Map<DataType1, DataType2> as the type. Without it it is just an object.

    Then in the for loop, use Map.Entry<DataType1, DataType2>

    I haven't tested this but it may work. You will need to find the types of the map and replace <DataType#> with the real data type.
     
    • Winner Winner x 1