NoSuchMethodError with YamlConfiguration

Discussion in 'Plugin Development' started by CubieX, Jan 26, 2015.

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

    CubieX

    I'm getting the above mentioned exception upon loading the configuration of a yml file.

    Code:
    Code:
    // Look for defaults in the jar
          Reader defConfigStream = null;
    
          try
          {
             defConfigStream = new InputStreamReader(plugin.getResource(playerListFileName), "UTF-8");
    
             if (defConfigStream != null)
             {
                YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
                playerListCfg.setDefaults(defConfig);
             }
          }
    Error happens in this line:
    Code:
    YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
    I have not coded plugins since after 1.7.2 was released.
    So I might miss something due to recent API changes.
    I'm building against Bukit 1.7.9 and have updated my standard config handler to use a Reader instead of the ambiguous InputStreamReader.
    But now this error came up and I don't know why.
    The overload for a "Reader" argument in the ".loadConfiguration()" method shows up in Eclipse intellisense
    and the API docs also say, that "Reader" is a valid argument type.
    But when loading the plugin, it crashes at this statement.

    The Exception:
    Code:
    java.lang.NoSuchMethodError: org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(Ljava/io/Reader;)Lorg/bukkit/configuration/file/YamlConfiguration;
       at com.github.CubieX.PreviousName.PNConfigHandler.reloadPlayerListFile(PNConfigHandler.java:86) ~[?:?]
       at com.github.CubieX.PreviousName.PNConfigHandler.initConfig(PNConfigHandler.java:36) ~[?:?]
       at com.github.CubieX.PreviousName.PNConfigHandler.<init>(PNConfigHandler.java:27) ~[?:?]
       at com.github.CubieX.PreviousName.PreviousName.onEnable(PreviousName.java:36) ~[?:?]
       at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:218) ~[craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
       at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:457) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
       at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:384) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
       at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugin(CraftServer.java:298) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
       at org.bukkit.craftbukkit.v1_7_R1.CraftServer.enablePlugins(CraftServer.java:280) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
       at net.minecraft.server.v1_7_R1.MinecraftServer.m(MinecraftServer.java:342) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
       at net.minecraft.server.v1_7_R1.MinecraftServer.g(MinecraftServer.java:319) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
       at net.minecraft.server.v1_7_R1.MinecraftServer.a(MinecraftServer.java:275) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
       at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.java:175) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
       at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:424) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
       at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    
    
     
  2. Offline

    Skionz

    @CubieX Which version of Bukkit are you compiling with?
     
  3. Code:java
    1.  
    2. saveResource("myresource.yml", false);
    3.  
     
  4. Offline

    1Rogue

  5. Offline

    CubieX

    loadConfiguration(InputStream) is deprecated. Until now I did it the way you suggested.
    But now I want to use a Reader instead to avoid the deprecated method.
    And yes, I know that deprecated does not mean I may not use it.
    But you are encouraged to not use deprecated methods in new designs if an alternative is available.

    But I don't understand the error here.
    Or was the "Reder" overload introduced with 1.7.10?
    I'm not able to download dev builds of Bukkit 1.7.10 atm. It says:
    For all dev builds. So I can't try it with 1.7.10.
     
  6. Offline

    1Rogue

    You'd need to build your own bukkit from github for 1.7.10

    As for the error, save it to a file first then and use a File reference.
     
  7. Offline

    Xtreme727

    isn't it FileConfiguration defConfig = YamlConfiguration...stuffhere?

    Edit: Nevah mind, I see whats trynna happen
     
  8. Offline

    CubieX

    This is my entire method:
    Code:
    // Create file with defaults or reload from disk if existing
       public void reloadPlayerListFile()
       {
          if (null == playerListFile)
          {
             playerListFile = new File(plugin.getDataFolder(), playerListFileName);
          }
          playerListCfg = YamlConfiguration.loadConfiguration(playerListFile);
    
          // Look for defaults in the jar
          Reader defConfigStream = null;
    
          try
          {
             defConfigStream = new InputStreamReader(plugin.getResource(playerListFileName), "UTF-8");
    
             if (null != defConfigStream)
             {
                YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream); // FIXME crash
                playerListCfg.setDefaults(defConfig);
             }
          }
          catch (UnsupportedEncodingException e)
          {        
             //e.printStackTrace();
             PreviousName.log.severe(PreviousName.logPrefix + "Invalid encoding exception upon opening playerListFile!");
          }     
       }

    So I first create a file reference and then look for a file with defaults in my plugin
    to save those default values to the file referenced above.
    This is the way I did it until now. But with passing an InputStream instead of a Reader.

    And your suggestion is to write an empty file to disk an then fill it with the defaults?
     
  9. Offline

    1Rogue

    Either that, or store a default copy of the file and use JavaPlugin#saveResource to write it to your relevant file.
     
  10. Offline

    timtower Administrator Administrator Moderator

  11. Offline

    CubieX

    I'll try that instead. Thanks.
     
Thread Status:
Not open for further replies.

Share This Page