Event & MySQL integration problem.

Discussion in 'Spigot Plugin Development' started by Haralil, May 17, 2016.

Thread Status:
Not open for further replies.
  1. So, i've been trying to make some level system plugin and i want to use MySQL. And now i am having troubles with it. I've tried to do anything, but everytime i get NullPointerException. So, please, if someone can help me - please help. Code here: http://pastebin.com/810z2aiL
  2. Code (Text):
    int playerLevel = rs.getInt(playerJoined);
    Heuuurgh... Here you must give the name of the colomn not the player name. In your example I think it rs.getInt("playerLevel");
  3. Thanks, but this not fixed the problem. Still get NullPointerException.

    ps. added the stacktrace http://pastebin.com/LwCQhdWQ
  4. I would suggest using UUIDs instead of the player name. If the player changes their name, the UUID is still the same. To your error: I dont know, if this fixes the error, but make the Connection static.
  5. Exactly! Use UUIDs, what you have now is 'converting' the player object into a string. This includes the player's position AND their name! If you were to do it this way (not recommended) you would use Player#getName(). You're most likely getting a NPE because the player's position will change (they tend to move around). ;)
    • Agree Agree x 1
  6. I will use custom launcher, so i don't need to use UUID. And making connection static don't fix the problem.
  7. This is my class, which i always use: http://pastebin.com/AwWQfuVM
  8. Code (Text):
    String playerJoined = event.getPlayer().toString()
    this probably isn't causing your NPE, but I think you meant this to be event.getPlayer().getName(). toString() is not the same.

    Unless someone can tell you the problem by eyeballing it, which some on this forum can, your stacktrace/code is insufficient to find the line that it's on.
    Code (Text):
    [21:38:02 WARN]:        at xyz.bymaximp.spigotpl.Main$OnPlayerJoin.onPlayerJoin(Main.java:46)
    which in the code you provided, is just a logger call, and not in onPlayerJoin(). Can you recompile and get a new stacktrace and figure out the offending line?
  9. I've tried to do as you said, and this don't work too. Still get NPE.
    I've recompiled the plugin, like, 10 times. I can try to rewrite it, but IDK will it help or not. Stacktrace on every recompile is not different than other.
  10. Show us your updated code.
  11. No problem, bruh: *removed for no source code leak xdd*
    #11 Haralil, May 17, 2016
    Last edited: May 18, 2016
  12. Have you verified that your database has successfully responded to your queries? If it has, try removing single quotes in your query string then attempt to join again. Also, post your updated exception.
    • Agree Agree x 1
  13. don't rewrite it. but the stacktrace you linked earlier on this thread does not correspond to the code, maybe you can try pasting a newer stacktrace? it's much easier to find the cause of an NPE when you know the line that it's on.
  14. Well, guys, i've just fixed problem myself and i dunno how did i do that. Just it fixed itself somehow xd
    Thanks anyone for support!
Thread Status:
Not open for further replies.