• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Null Pointer Exception in JTable

 
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)
{
......
}
}
 
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.
 
Paper beats rock. Scissors beats tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic