This week's book / license giveaways are in the JDBC and Relational Databases and Java in General forums.
We're giving away four copies each of PostGIS in Action and Java Advanced Topics Training and have the authors on-line!
See this thread and this one for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Null Pointer Exception in JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Null Pointer Exception in JTable" Watch "Null Pointer Exception in JTable" New topic

Null Pointer Exception in JTable

Swati krishnan

Joined: Feb 09, 2001
Posts: 11
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()
fly = new Data("db.db");
int recordCount;

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

catch (IOException e)


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

Joined: Jun 02, 2000
Posts: 244
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.
jQuery in Action, 2nd edition
subject: Null Pointer Exception in JTable