Can Red or one of you fine Upstanding People Kindly Explain whan this means? (a bunch or Errors)

  • java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at pluginapi.PluginEventHandler.triggerEvent(SourceFile:166)
    at aF.b.a(SourceFile:171)
    at aF.b.messageReceived(SourceFile:121)
    at k.e.a(SourceFile:109)
    at k.c.run(SourceFile:65)
    Caused by: java.lang.IllegalStateException: No serializer found for class l.x
    at de.jiw.network.serializing.Serializer.getClone(Serializer.java:125)
    at k.c.b(SourceFile:51)
    at k.e.a(SourceFile:113)
    at k.b.send(SourceFile:48)
    at k.b.send(SourceFile:43)
    at pluginapi.manager.PluginGuiManager.updateGuiTextField(SourceFile:167)
    at net.risingworld.api.gui.GuiTextField.updateTextField(GuiTextField.java:201)
    at net.risingworld.api.gui.GuiTextField.setText(GuiTextField.java:53)
    at EffNet.EffNet.onCommand(EffNet.java:133)
    ... 9 more

  • Why is there an error in on 80?

  • A) There might be more than one reason for an error in line 80; knowing the exact error reported would help. One of the most common reasons and the first coming to my mind is that the result of p.getAttribute("money") cannot be cast to an int.


    This may happen for instance if the attribute "money" is not set for that player.


    If I understand correctly the code, that attribute is initially set in line 60, upon retrieving the player money amount from the DB; however, it is only set if an amount is retrieved; if in the DB there is no row for that player, if(result.next()) in line 55 fails and the attribute is not set, causing an error in line 80.


    Can a row for a certain player be lacking in the DB? Sure, as the INSERT query in line 39 is never executed. So, it seems to me that no row is ever created in the DB. It seems to me that a db.executeUpdate(query); statement is missing in line 40 (but see C) below).


    This, presumably..., for the line 80 error. There are a few other issues in your code.


    B) An SQLite connection is open in line 20 of onEnable(), but another one is open and used in line 50 of the PlayerCommandEvent event. Having multiple connections to the same DB is possible, but is usually unnecessary (and a source of troubles).


    As Database db is a field of the class and is available to all its (non-static) methods, I do not see any reason to open a second connection with the same data base (and, in addition, to do this each time a player types a command in the chat, even a command totally unrelated with your plug-in).


    So, unless I am missing something, I would remove the content of line 50.


    C) It seems to me that the query in line 39 would not do what I presume you want to do. In line 39, I presume you want to add a new record with an initial default amount of money, but only if the player is a new player who never logged on the server before; I don't think you want to add another row for a player each time that player logs on. But this is what the query in line 39 would do.


    It is possible to check if a row for that player already exists and add a new one if none is found in several explicit steps, but the more compact and quickest way is to use SQL itself:


    1. Adding a PRIMARY KEY clause to the player_name column will force that column to have unique values, i.e. there can be only one row for each player, attempting to insert a second row for the same player would cause an error:
    'player_name' CHAR(64) NOT NULL DEFAULT ('[NoName]') PRIMARY KEY,
    (this would also create an index on 'player_name' speeding up queries based on it, which presumably is your main search criterion).


    2. Adding an OR IGNORE clause to the query in line 39:
    "INSERT OR IGNORE INTO Money ('player_name', 'Player_money') VALUES ('"+playerName+"', 2000);"
    will add a new row if there is no row for that player, while ignoring the resulting error and skipping the INSERT itself if a row already exists for him.


    At that point, a row (and only one) surely exists for that player in the DB. Here, in the PlayerSpawnEvent event, it is the right place for the query in lines 51 - 66, being sure to always set the "money" attribute, even if the query fails (because of an error or for whatever reason). For instance by unconditionally set it to a default value (0?) before the query or in the catch block.


    (Incidentally, in this way the SQL query (which is potentially expensive resource-wise) is executed at most once for each player login.)


    D) A small optimisation detail for the query in line 104: you are already sure that the "player_name" for the row to update is already the needed one (the WHERE clause ensures this), then the first value set is useless and it is enough to do:
    "UPDATE Money SET Player_money=666 WHERE player_name = '"+playerName+"'"


    The moral of the story: a reasonable familiarity with SQL is important: RTFM!! ;)

  • I temporalily took that out, i am aware of that, The database works like its supposed to., it reads Writes and updates, I get this error:



    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at pluginapi.PluginEventHandler.triggerEvent(SourceFile:166)
    at aF.b.a(SourceFile:171)
    at aF.b.messageReceived(SourceFile:121)
    at k.e.a(SourceFile:109)
    at k.c.run(SourceFile:65)


    Caused by: java.lang.NullPointerException
    at Test.Test.onCommand(Test.java:83)
    ... 9 more
    when i Comment it out, the plugin works, when i put it in, it Errors out.


    i looked up the error, how do I set it to null???


    There is data in the database, i put some in for testing, i have to check if the user is new :D that is why onSpawn isn't finished. :)

  • i looked up the error, how do I set it to null???

    A NullPointerException indicates that you tried to access a variable or a value which is null. Especially when it comes to attributes, it does throw a NullPointerException if you try to access an attribute which does not exist. Although you can cast an attribute and check if it's null afterwards, but this does only work for objects, not for primitive data types. For example:

    Java
    //This does work, "value1" will be null if this
    //attribute is not set
    String value1 = (String)player.getAttribute("value1");
    //This throws a NullPointerException if the
    //attribute is not set
    int value2 = (int)player.getAttribute("value2");


    The next update introduces a convenient method "hasAttribute()" which can be used to check if an attribute is already set. But it's always favorable to make sure that an attribute is already set when accessing it (even if you just set a default value in the PlayerConnectEvent or PlayerSpawnEvent).

  • I Think I set the attribute in line 11, and line 33 is SUPPOSED to retrive it, the database does read the data, I built a simple one and re-wrote code around it. is this Correct? Or do I have to define it somewhere else?

  • try this

    Yahgiggle Steam Signature, real name Deon Hamilton :thumbsup: Server @ ip 139.99.136.76:4255 Name (The Federation of territory) Unity :thumbsup:

    If at first your code does not work call it version 0.1 with the odd bug :thinking:

    My Own Website




    31245-logo-png

    Edited once, last by yahgiggle ().

  • I used Miarre's help, Red's help, yahgiggle's help, It will NOT work, it stopped the Null error, that went away, It seems to completely ignore the

    • if(result.next())

    block.


    Iwish I knew what the problem is, Everyone has their database working, My plugin doesn;t want to work for some reason


    I am at a loss right now, i want to get the basic Mecahincs working so I can move on. if anyone has the time to go line by line and see why it will not work please feel free to do so. i will fix the line at player spwan, that is an easy fix.. pleade help me get this working, it has been a week nd stil getting NOTHING

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!