SQLibrary Crash on Server Start

Discussion in 'Plugin Development' started by kmccmk9, Jun 25, 2013.

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

    kmccmk9

    Hello, I am trying to use PatPeter's SQLibrary. However, when installed onto the server without my plugin everything is fine. When I add my plugin, my plugin crashes with this error:

    Code:
    06-25 20:38:43 [INFO] Starting minecraft server version 1.5.2
    2013-06-25 20:38:43 [INFO] Loading properties
    2013-06-25 20:38:43 [INFO] Default game type: SURVIVAL
    2013-06-25 20:38:43 [INFO] Generating keypair
    2013-06-25 20:38:43 [INFO] Starting Minecraft server on *:25565
    2013-06-25 20:38:43 [INFO] This server is running CraftBukkit version git-Bukkit-1.5.2-R1.0-b2788jnks (MC: 1.5.2) (Implementing API version 1.5.2-R1.0)
    2013-06-25 20:38:44 [SEVERE] Could not load 'plugins\HDSkinner.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError: lib/PatPeter/SQLibrary/Database
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:184)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
        at org.bukkit.craftbukkit.v1_5_R3.CraftServer.loadPlugins(CraftServer.java:239)
        at org.bukkit.craftbukkit.v1_5_R3.CraftServer.<init>(CraftServer.java:217)
        at net.minecraft.server.v1_5_R3.PlayerList.<init>(PlayerList.java:55)
        at net.minecraft.server.v1_5_R3.DedicatedPlayerList.<init>(SourceFile:11)
        at net.minecraft.server.v1_5_R3.DedicatedServer.init(DedicatedServer.java:106)
        at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java:382)
        at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:573)
    Caused by: java.lang.NoClassDefFoundError: lib/PatPeter/SQLibrary/Database
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:173)
        ... 9 more
    Caused by: java.lang.ClassNotFoundException: lib.PatPeter.SQLibrary.Database
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at org.bukkit.plugin.java.PluginClassLoader.findClass0(PluginClassLoader.java:80)
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:53)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 12 more
    This makes me believe there is something wrong with my code. So below is my code as well. However I have no errors in my IDE so I have no idea what is wrong.

    Code:java
    1. package com.kmccmk9.HDSkinner;
    2.  
    3. import java.sql.SQLException;
    4. import java.util.logging.Logger;
    5.  
    6. import lib.PatPeter.SQLibrary.Database;
    7.  
    8. import org.bukkit.ChatColor;
    9. import org.bukkit.Server;
    10. import org.bukkit.command.Command;
    11. import org.bukkit.command.CommandSender;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14. import org.getspout.spoutapi.SpoutManager;
    15. import org.getspout.spoutapi.player.SpoutPlayer;
    16. import lib.PatPeter.SQLibrary.*;
    17. import lib.PatPeter.SQLibrary.Builders.MySQL.Table;
    18.  
    19. public class HDSkinner extends JavaPlugin {
    20. //Variables
    21. Server server;
    22. Database sql;
    23. Table skins;
    24.  
    25. public void onDisable()
    26. {
    27. System.out.print("HDSkinner is disabled");
    28. }
    29.  
    30. public void onEnable()
    31. {
    32. sql = new SQLite(Logger.getLogger("Minecraft"), "[HDSkinner] ", this.getDataFolder().getAbsolutePath(), "HDSkinner", ".sqlite");
    33. if (!skins.exists) {
    34. try {
    35. skins.create();
    36. } catch (SQLException e) {
    37. // TODO Auto-generated catch block
    38. e.printStackTrace();
    39. }
    40. }
    41. System.out.print("HDSkinner is enabled");
    42. server = this.getServer();
    43. }
    44.  
    45. public boolean onCommand(CommandSender sender,Command command, String commandLabel,String args[])
    46. {
    47.  
    48. if (sender instanceof Player)
    49. {
    50. Player player = (Player) sender;
    51. SpoutPlayer splayer = SpoutManager.getPlayer(player);
    52. if(commandLabel.equalsIgnoreCase("skin"))
    53. {
    54. if (args.length == 1)
    55. {
    56. if (args[0].equalsIgnoreCase("help"))
    57. {
    58. player.sendMessage(ChatColor.BLUE + "Type the command skin followed by the url to change your skin to that url.");
    59. }
    60. else
    61. {
    62. splayer.setSkin(args[0]);
    63. }
    64. }
    65. else
    66. {
    67. player.sendMessage(ChatColor.DARK_RED + "Arguments mismatch. Type the skin command followed by help.");
    68. }
    69. }
    70. if(commandLabel.equalsIgnoreCase("cape"))
    71. {
    72. if (args.length == 1)
    73. {
    74. if (args[0].equalsIgnoreCase("help"))
    75. {
    76. player.sendMessage(ChatColor.BLUE + "Type the command cape followed by the url to change your cape to that url.");
    77. }
    78. else
    79. {
    80. try {
    81. sql.query("INSERT INTO userdata (user,skin) VALUES (" + sender.toString() + ',' + args[0].toString() + ") WHERE user=" + sender.toString());
    82. } catch (SQLException e) {
    83. // TODO Auto-generated catch block
    84. e.printStackTrace();
    85. }
    86. splayer.setCape(args[0]);
    87. try {
    88. server.broadcastMessage(sql.query("SELECT * userdata").toString());
    89. } catch (SQLException e) {
    90. // TODO Auto-generated catch block
    91. e.printStackTrace();
    92. }
    93. }
    94. }
    95. else
    96. {
    97. player.sendMessage(ChatColor.DARK_RED + "Arguments mismatch. Type the cape command followed by help.");
    98. }
    99. }
    100. }
    101. return true;
    102. }
    103.  
    104. public void openDatabase() {
    105. if (!sql.open())
    106. sql.open();
    107. skins.name = "userdata";
    108. if (!skins.exists) {
    109. try {
    110. sql.query("CREATE TABLE userdata(user String, skin String, cape String)");
    111. } catch (SQLException e) {
    112. // TODO Auto-generated catch block
    113. e.printStackTrace();
    114. }
    115. }
    116. }
    117.  
    118. public void closeDatabase() {
    119. if (sql.open())
    120. sql.close();
    121. }
    122.  
    123. public void setupDatabase() {
    124.  
    125. }
    126.  
    127. }
    128.  
     
  2. Offline

    ProtoTempus

    kmccmk9

    It cant find the SQLibrary, add the SQLibrary.jar to your plugins folder.
     
  3. Offline

    kmccmk9

    ProtoTempus It is. That's what I don't understand.


    ProtoTempus what futher makes no sense is that without my plugin, the SQLibrary starts and enables properly.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  4. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    Need to add it to your depend listing in plugin.yml
     
    dillyg10 likes this.
  5. Offline

    kmccmk9

    Oh that's what it is I will give it a shot.


    Thank you that fixed the problem.


    Hey, can you help me figure out this error?

    Code:
    lang.NullPointerException
        at com.kmccmk9.HDSkinner.HDSkinner.openDatabase(HDSkinner.java:107)
        at com.kmccmk9.HDSkinner.HDSkinner.onEnable(HDSkinner.java:33)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:457)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:381)
        at org.bukkit.craftbukkit.v1_5_R3.CraftServer.loadPlugin(CraftServer.java:282)
        at org.bukkit.craftbukkit.v1_5_R3.CraftServer.enablePlugins(CraftServer.java:264)
        at net.minecraft.server.v1_5_R3.MinecraftServer.j(MinecraftServer.java:304)
        at net.minecraft.server.v1_5_R3.MinecraftServer.e(MinecraftServer.java:283)
        at net.minecraft.server.v1_5_R3.MinecraftServer.a(MinecraftServer.java:243)
        at net.minecraft.server.v1_5_R3.DedicatedServer.init(DedicatedServer.java:151)
        at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java:382)
        at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:573)
    This is the function it is talking about...
    Code:java
    1. public void openDatabase() {
    2. if (!sql.open())
    3. sql.open();
    4. skins.name = "userdata";
    5. if (!skins.exists) {
    6. try {
    7. sql.query("CREATE TABLE userdata(user String, skin String, cape String)");
    8. } catch (SQLException e) {
    9. // TODO Auto-generated catch block
    10. e.printStackTrace();
    11. }
    12. }
    13. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  6. Offline

    skipperguy12

    kmccmk9
    Which line in that method is line 107?
    Sorry for not reading the code in OP, but, the only thing I see that can be null is sql or the method open() in sql.

    Offtopic: Why not just use JDBC instead of using a SQL library? Not saying it's bad, just want to know the benefits to it :p
     
  7. Offline

    kmccmk9


    skins.name = "userdata"; is line 107. I agree with you. I was following the developer tutorial so I was only aware of SQLibrary. What is JDBC?
     
  8. Offline

    skipperguy12

    kmccmk9
    It's the driver for SQL, without any libraries.

    I read up on SqlLibrary just now though, already implementing it into my plugins! Looks really neat! :D

    Assuming that line 33 of HDSkinner.java uses skins, it's null. Skins or skins.name (most likely skins.name) is null.
    Do a null check like so: if(variable == null) Bukkit.getLogger().info("Here you'll write out a dandy message like: ERROR! LINE X variable IS NULL!");

    kmccmk9
    Also, one thing, how does setting sql to a new database not give you an error saying type mismatch?
    I defined a Database sql variable at the top, then in onEnable set it like this:
    sql = new MySQL(Bukkit.getLogger(), "", dbconfig.getHost(), dbconfig.getPort(), dbconfig.getDB(), dbconfig.getUser(), dbconfig.getPassword());

    Why do I get "Type mismatch: cannot convert from MySql to Database"?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  9. Offline

    kmccmk9


    I'm not sure, I'm using SQlite and I'm using this code in my onEnable()

    Code:java
    1. sql = new SQLite(Logger.getLogger("Minecraft"), "[HDSkinner] ", this.getDataFolder().getAbsolutePath(), "HDSkinner", ".sqlite");


    But I believe you also have additional parameters like a user and pass.
     
  10. Offline

    ProtoTempus


    My guess is that for MYSQL you accidentally imported the one from Java rather than from SQLibrary. Check your imports.
     
  11. Offline

    skipperguy12

  12. Offline

    kmccmk9

    Okay I'm having a problem with a query. I'm using SQLite and this should work but I keep getting the following error
    Code:
    2013-06-27 03:07:16 [INFO] kmccmk9 issued server command: /skin https://dl.dropboxusercontent.com/u/10429987/TechMan.png
    2013-06-27 03:07:16 [INFO] INSERT INTO userdata (user,skin) VALUES (kmccmk9,https://dl.dropboxusercontent.com/u/10429987/TechMan.png) WHERE user=kmccmk9
    2013-06-27 03:07:16 [SEVERE] java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (unrecognized token: ":")
    2013-06-27 03:07:16 [SEVERE]    at org.sqlite.DB.newSQLException(DB.java:383)
    2013-06-27 03:07:16 [SEVERE]    at org.sqlite.DB.newSQLException(DB.java:387)
    2013-06-27 03:07:16 [SEVERE]    at org.sqlite.DB.throwex(DB.java:374)
    2013-06-27 03:07:16 [SEVERE]    at org.sqlite.NativeDB.prepare(Native Method)
    2013-06-27 03:07:16 [SEVERE]    at org.sqlite.DB.prepare(DB.java:123)
    2013-06-27 03:07:16 [SEVERE]    at org.sqlite.Stmt.execute(Stmt.java:113)
    2013-06-27 03:07:16 [SEVERE]    at lib.PatPeter.SQLibrary.Database.query(Database.java:235)
    2013-06-27 03:07:16 [SEVERE]    at com.kmccmk9.HDSkinner.HDSkinner.onCommand(HDSkinner.java:58)
    2013-06-27 03:07:16 [SEVERE]    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    2013-06-27 03:07:16 [SEVERE]    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:189)
    2013-06-27 03:07:16 [SEVERE]    at org.bukkit.craftbukkit.v1_5_R3.CraftServer.dispatchCommand(CraftServer.java:523)
    2013-06-27 03:07:16 [SEVERE]    at net.minecraft.server.v1_5_R3.PlayerConnection.handleCommand(PlayerConnection.java:971)
    2013-06-27 03:07:16 [SEVERE]    at net.minecraft.server.v1_5_R3.PlayerConnection.chat(PlayerConnection.java:889)
    2013-06-27 03:07:16 [SEVERE]    at net.minecraft.server.v1_5_R3.PlayerConnection.a(PlayerConnection.java:846)
    2013-06-27 03:07:16 [SEVERE]    at org.getspout.spout.SpoutPlayerConnection.a(SpoutPlayerConnection.java:120)
    2013-06-27 03:07:16 [SEVERE]    at net.minecraft.server.v1_5_R3.Packet3Chat.handle(Packet3Chat.java:44)
    2013-06-27 03:07:16 [SEVERE]    at net.minecraft.server.v1_5_R3.NetworkManager.b(NetworkManager.java:292)
    2013-06-27 03:07:16 [SEVERE]    at net.minecraft.server.v1_5_R3.PlayerConnection.d(PlayerConnection.java:115)
    2013-06-27 03:07:16 [SEVERE]    at org.getspout.spout.SpoutPlayerConnection.d(SpoutPlayerConnection.java:195)
    2013-06-27 03:07:16 [SEVERE]    at net.minecraft.server.v1_5_R3.ServerConnection.b(SourceFile:35)
    2013-06-27 03:07:16 [SEVERE]    at net.minecraft.server.v1_5_R3.DedicatedServerConnection.b(SourceFile:30)
    2013-06-27 03:07:16 [SEVERE]    at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:581)
    2013-06-27 03:07:16 [SEVERE]    at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:226)
    2013-06-27 03:07:16 [SEVERE]    at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:477)
    2013-06-27 03:07:16 [SEVERE]    at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java:410)
    2013-06-27 03:07:16 [SEVERE]    at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:573)
    2013-06-27 03:07:18 [INFO] kmccmk9 lost connection: disconnect.quitting
    
    It does not seem to like the : in the url. However, the column type is set to BLOB so it should accept the data as it is. Can anyone help with this? The query is shown below:
    Code:
    INSERT INTO userdata (user,skin) VALUES (kmccmk9,[URL]https://dl.dropboxusercontent.com/u/10429987/TechMan.png[/URL]) WHERE user=kmccmk9
     
Thread Status:
Not open for further replies.

Share This Page