[Solved] File loading problem (and casting String to ArrayList for some reason?)

Discussion in 'Plugin Development' started by kuzi117, Oct 29, 2011.

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

    kuzi117

    It would seem that I'm trying to retrieve a list when something's actually a string.
    Or there's a problem with the way I'm loading a file. My code actually iterates through a few files. I just added a new one, it worked fine before, so it seems obvious that the problem would be in the file, but the file looks exactly as it should.
    Code:
    [WARNING] Unexpected exception while parsing console command
    org.bukkit.command.CommandException: Unhandled exception executing command 'permgui' in plugin PermGUI v0.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:163)
        at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:355)
        at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:351)
        at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:506)
        at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:485)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:374)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:417)
    Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.String
        at org.bukkit.configuration.file.YamlConfiguration.deserializeValues(YamlConfiguration.java:103)
        at org.bukkit.configuration.file.YamlConfiguration.deserializeValues(YamlConfiguration.java:100)
        at org.bukkit.configuration.file.YamlConfiguration.deserializeValues(YamlConfiguration.java:100)
        at org.bukkit.configuration.file.YamlConfiguration.deserializeValues(YamlConfiguration.java:100)
        at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:71)
        at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:143)
        at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:109)
        at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:229)
        at com.kuzi117.PermGUI.Loader.getNeededLength(Loader.java:37)
        at com.kuzi117.PermGUI.Loader.getData(Loader.java:62)
        at com.kuzi117.PermGUI.GUI.initSpane(GUI.java:149)
        at com.kuzi117.PermGUI.GUI.<init>(GUI.java:93)
        at com.kuzi117.PermGUI.Handler.onCommand(Handler.java:94)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
        ... 7 more
    Any suggestions?
    Thanks in advance,
    kuzi117
     
  2. Need your code to be actually of any help.
     
  3. Offline

    kuzi117

    I figured as much, just didn't know what you'd really want. The first part in the stack that's actually mine is this :
    Code:
     private int getNeededLength() {
      int length = 0;
      for (Plugin plugin : pluginList){
       File permsFile = new File("plugins" + File.separator+ "PermGUI" + File.separator + "permfiles"+ File.separator + plugin.toString() + ".yml");
       if (permsFile.exists()) {
        YamlConfiguration config = YamlConfiguration.loadConfiguration(permsFile);
        List<String> keys = getKeys(config);
        length += keys.size();
       }
      }
      return length;
     }
    
     }
    return length;
     }
    Which in turn references this:
    Code:
     private List<String> getKeys(YamlConfiguration config) {
      List<String> permKeys = new ArrayList<String>();
      Set<String> allKeys = config.getKeys(true);
      for(String key : allKeys) {
       if (!config.isConfigurationSection(key)) {
        permKeys.add(key);
       }
      }
      return permKeys;
     }
    
     
  4. Which line is
    com.kuzi117.PermGUI.Loader.getNeededLength(Loader.java:37)?

    Also need your getData() method.
     
  5. Offline

    kuzi117

    Code:
     private int getNeededLength() {
      int length = 0;
      for (Plugin plugin : pluginList){
       File permsFile = new File("plugins" + File.separator+ "PermGUI" + File.separator + "permfiles"+ File.separator + plugin.toString() + ".yml");
       if (permsFile.exists()) {
        YamlConfiguration config = YamlConfiguration.loadConfiguration(permsFile); //line 37
        List<String> keys = getKeys(config);
        length += keys.size();
       }
    
    See, I thought it had something to do with loading, but the file should be correct.
    Code:
     Object[][] getData() {
      newData = new Object[getNeededLength()][3]; //line 62
      int counter = 0;
    
      for (int i = 0; i < pluginList.length; i++){
       File permsFile = new File("plugins" + File.separator+ "PermGUI" + File.separator + "permfiles"+ File.separator + pluginList[i].toString() + ".yml");
       if (permsFile.exists()) {
        YamlConfiguration config = YamlConfiguration.loadConfiguration(permsFile);
        List<String> perms = getPerms(config);
        for (int n = 0; n < perms.size(); n++) {
         newData[n+counter][0] = config.getString(perms.get(n), "Description not found.");
         if (perms.get(n).endsWith(".(unused)")){
          newData[n+counter][1] = perms.get(n).substring(0, perms.get(n).length()-9);
         }
         else {
          newData[n+counter][1] = perms.get(n);
         }
        }
        counter += perms.size();
       }
      }
      for (int i = 0; i < getNeededLength(); i++) {
       newData[i][2] = new Boolean(false);
      }
      return newData;
     }
      }
      return length;
     }
    
     
  6. Well, either your config file is mal-formatted or there is a bug in the Bukkit API.
     
  7. Offline

    kuzi117

    K, that's the conclusion I came to as well. Just thought I was missing something.
     
Thread Status:
Not open for further replies.

Share This Page