I am trying to access a local database and pull the data out and store it in an array...but I keep receiving a null pointer exception, please help?
int rows = 0;
int colNum = res.getMetaData().getColumnCount();
res.beforeFirst();
while(res.next()){
rows++;
for(int i = 1; i < colNum; i++){
teamTable[rows - 1][colNum - 1] = res.getString("Team");
teamTable[rows - 1][colNum - 1] = res.getInt("Goal Difference");
teamTable[rows - 1][colNum - 1] = res.getInt("Points");
System.out.println(teamTable[rows - 1][colNum - 1]);
}
}
My bet is that you haven't initialized the teamTable
multidimensional array properly. Does it have enough rows? Have you called teamTable[rowIndex] = new Object[colNum];
? If you forgot about the second one, or teamTable
is just null, then you get a NullPointerException.
If this isn't clear, then read a tutorial about Java multidimensional arrays, e.g. the answers for this question: Syntax for creating a two-dimensional array