Hello everyone,
What im trying to do is that the MySQL class retrieves characters from a certain account id and inserts them into a multi-dimentional array. It does this inside the getCharacters function. But when i insert the values into the multi-dimentional array and run my application it give's a null pointer exception on a certain line. This is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| public String[][] getCharacters(int accId) { String[][] characters = null; try { Statement st = con.createStatement(); ResultSet rs = st.executeQuery("SELECT * FROM `characters` WHERE `account_id`="+ accId); int i = 1; while(rs.next()) { String username = rs.getString("username"); int level = rs.getInt("level"); System.out.println("I: "+ i +" User:"+ username +", Lvl: "+ level); characters[i][0] = username; characters[i][1] = ""+ level; i++; } rs.close(); st.close(); } catch (SQLException e) { System.out.println("[Login Server][Error]: Error with retrieving characters: "+ e.getMessage()); } catch (Exception e) { System.out.println(""); } return characters; } |
NullPointerException happens on the following line: "characters[i ][0 ] = username;" (Note there are no spaces between the brackets but the forum views it as BB code)
Iv been stuck with this problem for 4 days now and im sirreusly stressing alot over it, iv asked a few application developers at my school if they could help out but they couldnt find the problem either. I hope someone know's what im doing wrong here and if possible send me a link or type some text informing me on what i did wrong and what i could do to prevent this from happening again..
Thanks in advance
