Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null Pointer Exception in JTable

 
Swati krishnan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my code to implement the FlyTableModel extending Abstract table Model
It compiles fine but I get the error "NullPointer Exception at
getColumnCount()", getRowCount() and getColumnName(int col)
at Runtime. What could be the problem

class FlyTableModel extends AbstractTableModel()
{
Data fly;
public void setResult()
{
try
{
fly = new Data("db.db");
int recordCount;

recordCount = fly.getRecordCount();
...Here all the dataInfo and Vector conversion
...

}
catch (IOException e)
{
System.out.println(e.getMessage());

}
}


public int getColumnCount()
{
return fly.getFieldInfo().length;

}
public int getRowCount()
{
return fly.getRecordCount();

}
public Object getValueAt(int row, int col)
{
.....
}
public String getColumnName(int col)
{
......
}
}
 
Paul Smiley
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to catch the Null pointer exception and print it out - it should tell you exactly what line it chokes on.
Maybe initialize recordCount to zero???
If I were to guess, I'd have to believe that some error was made in your binary file somehow. Take a look at it using a hex editor like hedit - you can get it for free on the web. Try to call invalidate() by itself before the call to getRecordCount() - if it's not public, make it public for testing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic