-
Small problem, help please?
Code :
java.lang.NullPointerException
at server.util.MysqlManager.checkVote(MysqlManager.java:43)
at server.model.players.Client.initialize(Client.java:81)
at server.model.players.PlayerHandler.process(PlayerHandler.java:186)
at server.Server.main(Server.java:176)
And below is section of code that it states.
Size 5 font = LINE 43
Code :
public static void checkVote(Client c) {
try {
[SIZE=5]Statement stmt = conn.createStatement();[/SIZE]
ResultSet rs = stmt
.executeQuery("SELECT COUNT(playerName) AS total FROM `votes` WHERE `playerName`= \""
+ c.playerName + "\" AND `recieved`= 0");
rs.first();
int total = rs.getInt("total");
if (total == 1) {
stmt.execute("UPDATE `votes` SET `recieved` = 1 WHERE `playerName` = '"
+ c.playerName + "'");
c.getItems().addItem(995, 10000000);
c.sendMessage("Thanks for voting! Please do so again in 24 hours!");
}
} catch (SQLException ex) {
System.out.println(ex);
}
}
Client.java - Line 81
Code :
private CombatAssistant combatAssistant = new CombatAssistant(this);
Size 5 Font = LINE 186
Code :
Client o1 = (Client) Server.playerHandler.players[i];
if(PlayerSave.saveGame(o1)){
System.out.println("Game saved for player "+players[i].playerName);
} else {
System.out.println("Could not save for "+players[i].playerName);
}
removePlayer(players[i]);
players[i] = null;
} else {
Client o = (Client) Server.playerHandler.players[i];
//if(o.g) {
if(!players[i].initialized) {
[B]players[i].initialize();[/B]
players[i].initialized = true;
}
else {
players[i].update();
}
Server.java - Line 176
It's on a Windows 64-bit VPS, so it's not like on Linux for capitalisation etc.
Any help?
Thanks.
-
Re: Small problem, help please?
Quote:
at server.util.MysqlManager.checkVote(MysqlManager.ja va:43)
What variable is null at line 43? Check back through the code to see why it has not been given a valid value.
-
Re: Small problem, help please?
I don't know what you mean.
I'll post my MysqlManager.java file, sec.
#2438939 - Pastie
-
Re: Small problem, help please?
Quote:
I don't know what you mean.
Do you know what a program variable is?
For example in the following line of code var is the variable and doSomething is a method:
var.doSomething()
If var has a null value you will get a NullPointerException on that line.
Look at line 43 in MysqlManager.java
What variables are on that line that can be null?
Add a println to print out the values of all that variables used on that line. For example for the line I showed above, I'd add this just before the line to show the value of var:
System.out.println("var=" + var);
-
Re: Small problem, help please?
I'm new at programming, so I don't really know all the ins and outs.
It appears Line 43 didn't turn into size 5, so you couldn't see it.
This is line 43 below:
Code :
Statement stmt = conn.createStatement();
-
Re: Small problem, help please?
Where does the variable conn get assigned a value?
The error message says it has a value of null. It needs to have a valid value that points to an object of the class that has the createStatement method.
-
Re: Small problem, help please?
Sorry for sounding like a complete noob, but where would I find this?
-
Re: Small problem, help please?
Assignment statements look like this:
conn = <HERE IS THE VALUE TO ASSIGN TO conn>;
Search your source code for statements with "conn =" or "conn="
Or better search for ALL the statements that use the variable: conn.
-
Re: Small problem, help please?
Oh wait, is it this?
Code :
public static Connection conn = null;
public static Statement statement = null;
public static ResultSet results = null;
-
Re: Small problem, help please?
As you can see from the code you posted, conn has a value of null.
It needs to have the address of a Connection object.
Where did you get this code from? You should go to that location or person and find out why the conn variable is not being given a valid value.
-
Re: Small problem, help please?
How would I assign it the address of a Connection object? b-(
I got it from here : [PI] Auto Donation System with Items - NEW
Is their anyway you can help me, because the OP isn't active anymore.
-
Re: Small problem, help please?
Quote:
How would I assign it the address of a Connection object?
Time for some studying.
Read up on how to do database programming. Go to this site and Find database
The Really Big Index
-
Re: Small problem, help please?
Uh, I hate when people say that.
I know I have to learn, but I can't learn if I don't know what to look at, change etc.
Do you have MSN/Skype so we could chat on there?
-
Re: Small problem, help please?
Quote:
Do you have MSN/Skype so we could chat on there?
If wouldn't do you any good. I would tell you the same thing. Read the tutorial and get an understanding about what a database is and how to use it.
There is a LOT to learn before you can write this program. There is no quick, easy short cut.
-
Re: Small problem, help please?
I can do MySQL databases but I don't know how to use them in my server.
All I need to do is set conn a value, how do I do it. It's not that complicated.
-
Re: Small problem, help please?
Also, I don't even know what part I'm supposed to be looking at on that website.
-
Re: Small problem, help please?
Quote:
what part I'm supposed to be looking at on that website.
The part about databases
-
Re: Small problem, help please?
-
Re: Small problem, help please?
Start with the first one and then do the second one.
-
Re: Small problem, help please?
It doesn't say anything about assigning a connection a value...
This is my SQL table.
CREATE TABLE `status` (
`id` INT(10) NOT NULL AUTO_INCREMENT,
`date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`username` VARCHAR(15) NULL,
`item` SMALLINT(5) NULL,
`quantity` SMALLINT(5) NULL,
`given` TINYINT(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
)
-
Re: Small problem, help please?
Sorry, I know nothing about SQL and how to use databases.
-
Re: Small problem, help please?
So you told me to read The Big Index because you don't know how to fix it? :3
-
Re: Small problem, help please?
I gave you the Big Index because you will be needing it for lots of Java programming problems.
Starting from the Big Index you can find the section where need specific information for today's problem.
Tomorrow with another problem, you'll start with the Big Index again, find the section you need help with and read from there.
If I'd given you the index to the page with the Connection class info. Tomorrow some one would have to give you the index to the page with the LinkedList class info. Next day the link to the page with the Painting info.
You can now find all that yourself by starting at the Big Index.
I hope that is not too hard for you to do.
-
Re: Small problem, help please?
So I need to go to the connection class info?
-
Re: Small problem, help please?
Did you look thru the code you posted a link to? The MysqlManager class definition.
Did you do a search for "conn =" in that code as I suggested back in post#8?