File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Null Pointer Exception in JTable

Swati krishnan
Greenhorn

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()
{
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

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Null Pointer Exception in JTable