Solved (found alternative) SQLibary: Need some Help

Discussion in 'Plugin Development' started by xdarcade, Aug 21, 2013.

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

    xdarcade

    Hey I have problems in my Plugin.
    When I run it I get the following error:
    Code:
    13:12:54 [INFO] [lottery] Enabling lottery v0.1
    13:12:54 [SCHWERWIEGEND] Error occurred while enabling lottery v0.1 (Is it up to date?)
    java.lang.NullPointerException
        at me.darcade.lottery.SQLitehandler.init(SQLitehandler.java:21)
        at me.darcade.lottery.lottery.onEnable(lottery.java:34)
        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_6_R2.CraftServer.loadPlugin(CraftServer.java:282)
        at org.bukkit.craftbukkit.v1_6_R2.CraftServer.enablePlugins(CraftServer.java:264)
        at net.minecraft.server.v1_6_R2.MinecraftServer.l(MinecraftServer.java:313)
        at net.minecraft.server.v1_6_R2.MinecraftServer.f(MinecraftServer.java:290)
        at net.minecraft.server.v1_6_R2.MinecraftServer.a(MinecraftServer.java:250)
        at net.minecraft.server.v1_6_R2.DedicatedServer.init(DedicatedServer.java:151)
        at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:391)
        at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    13:12:54 [INFO] [SQLibrary] Enabling SQLibrary v4.2
    13:12:54 [INFO] SQLibrary loaded.
    
    Here is where I call the function:

    Code:java
    1. @Override
    2. public void onEnable() {
    3. sqlitehandler.init(); //<--- Here it tells me is the error
    4.  
    5. PluginDescriptionFile descFile = this.getDescription();
    6. this.createConfig();
    7.  
    8. System.out.println("[PLUGINNAME] plugin enabled!");
    9. System.out.println("Plugin Version: " + descFile.getVersion());
    10. }


    Here is the Class:


    Code:java
    1. package me.darcade.lottery;
    2.  
    3. import java.sql.ResultSet;
    4. import java.sql.SQLException;
    5. import java.util.logging.Logger;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. import lib.PatPeter.SQLibrary.SQLite;
    11.  
    12. public class SQLitehandler extends JavaPlugin {
    13.  
    14. public SQLite sqlite;
    15. static final Logger log = Bukkit.getLogger();
    16.  
    17. private ResultSet result;
    18.  
    19. public void init() {
    20. sqlite = new SQLite(log, "lottery", this.getDataFolder()
    21. .getAbsolutePath(), "lotterydb", ".sqlite");
    22.  
    23. if (!sqlite.isOpen()) {
    24. sqlite.open();
    25. }
    26. return;
    27. }
    28.  
    29. public ResultSet doquery(String query) {
    30.  
    31. try {
    32. result = sqlite.query(query);
    33. } catch (SQLException e1) {
    34. // TODO Auto-generated catch block
    35. e1.printStackTrace();
    36. }
    37.  
    38. return result;
    39. }
    40. }
    41.  
     
  2. Offline

    LucasEmanuel

    xdarcade
    Since you haven't given us the entire code making it impossible for us to help you I'm going to guess your problem.

    Your sqlitehandler-reference is null since you haven't created a new Sqlitehandler-object.
     
  3. Did you ever create sqlitehandler?
     
  4. Offline

    xdarcade

    I created the object:


    Code:java
    1. package me.darcade.lottery;
    2.  
    3. import java.sql.ResultSet;
    4. import java.sql.SQLException;
    5. import java.util.Calendar;
    6. import java.util.List;
    7. import java.util.Random;
    8. import java.util.logging.Logger;
    9.  
    10. import org.bukkit.Bukkit;
    11. import org.bukkit.ChatColor;
    12. import org.bukkit.command.Command;
    13. import org.bukkit.command.CommandSender;
    14. import org.bukkit.entity.Player;
    15. import org.bukkit.inventory.ItemStack;
    16. import org.bukkit.plugin.PluginDescriptionFile;
    17. import org.bukkit.plugin.java.JavaPlugin;
    18.  
    19. import lib.PatPeter.SQLibrary.SQLite;
    20. import me.darcade.lottery.SQLitehandler;
    21.  
    22. public class lottery extends JavaPlugin {
    23.  
    24. SQLitehandler sqlitehandler = new SQLitehandler(); //<-------- HERE
    25. String rowcount;
    26.  
    27. @Override
    28. public void onDisable() {
    29.  
    30.  
    31.  
    32. sqlitehandler.sqlite.close();
    33. System.out.println("Lottery plugin disabled!");
    34.  
    35. }
    36.  
    37. @Override
    38. public void onEnable() {
    39.  
    40. sqlitehandler.init();
    41. sqlitehandler
    42. .doquery("CREATE TABLE IF NOT EXISTS lotterytable (username TEXT , lastlottery NUMERIC, PRIMARY KEY(username));");
    43.  
    44. PluginDescriptionFile descFile = this.getDescription();
    45. this.createConfig();
    46.  
    47. System.out.println("[Lottery] plugin enabled!");
    48. System.out.println("Plugin Version: " + descFile.getVersion());
    49. }




    EDIT:


    SOLVED I just used the sqlite api from java by using this tutorial
    http://www.tutorialspoint.com/sqlite/sqlite_java.htm

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
Thread Status:
Not open for further replies.

Share This Page