Solved The method size() is undefined for the type Object

Discussion in 'Plugin Development' started by xXLightbulbXx, Nov 1, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    xXLightbulbXx

    Hey, So i'm getting this error under .size()
    "The method size() is undefined for the type Object"
    Code:
    public static String InventoryToString(Inventory paramInventory)
      {
        String str1 = paramInventory.getSize() + ";";
        for (int i = 0; i < paramInventory.getSize(); i++)
        {
          ItemStack localItemStack = paramInventory.getItem(i);
          if (localItemStack != null)
          {
            String str2 = new String();
           
            String str3 = String.valueOf(localItemStack.getType().getId());
            Object localObject = localItemStack.getEnchantments();
            str2 = str2 + "t@" + str3;
            if (localItemStack.getDurability() != 0)
            {
              localObject = String.valueOf(localItemStack.getDurability());
              str2 = str2 + ":d@" + (String)localObject;
            }
            if (localItemStack.getAmount() != 1)
            {
              localObject = String.valueOf(localItemStack.getAmount());
              str2 = str2 + ":a@" + (String)localObject;
            }
            if ((localObject).size() > 0) {
              for (Map.Entry localEntry : (((Map<Enchantment, Integer>) localObject).entrySet())) {
                str2 = str2 + ":e@" + ((Enchantment)localEntry.getKey()).getId() + "@" + localEntry.getValue();
              }
            }
            str1 = str1 + i + "#" + str2 + ";";
          }
        }
        return str1;
      }
     
  2. Offline

    MasterDoctor

    Why not this?
    Code:
    localObject.getSize();
     
  3. Offline

    Scimiguy

    I think you want Inventory#getContents()
    Then use getSize() if needed
     
  4. Offline

    xXLightbulbXx

    None of those are working.
     
  5. Offline

    teej107

    @xXLightbulbXx Because you are referencing the object as an Object and Object doesn't have that method.
     
Thread Status:
Not open for further replies.

Share This Page