• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

To Dave Macarthy, working of JTable

 
Pratibha Gayake
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Dave,
I am facing following problem while using MVC pattern for constructing JTable (This is in line with your earlier post for MVC pattern);
/* follwoing is MainModel class
public class MainModel{
private String[] columnNames;
private DataInfo[] rows;
//getter and setter methods for columnNames and rows
}
/*following in FbnTableController class which uses setter method of MainModel*/
public class FbnTableController{
private String[] names;
private DataInfo[] dInfo;
private Data dt;
private FieldInfo[] field;
//this constructor sets the values of coulmnNames and rows in
//MainModel
public FbnTableController(){
try{
dt = new Data("db/db");
dInfo = dt.criteriaFind("Origin airport='SFO'");
field = dt.getFieldInfo();
for(int i=0;i<field.length;i++){>
//in following loop,name[] fills with field name
names[i] = field[i].getName();
}
mainModel.setColumnNames(names);
mainModel.setTableRows(dInfo);
}
catch(Exception e){}
}
}
/*Following is FbnTable which extends AbstarctTableModel*/
public class FbnTable extends AbstractTableModel{
private String columnNames;
private DataInfo[] rows;
//Follwoing instance of FbnTableController now set
// the columnNames and rows in MainModel
private FbnTableController cont = new FbnTableController();
public FbnTable(MainModel model){
colNames = mainModel.getColumnNames();
//Problem is here: Here it gives NullpointerException, colNames gets null value even after setting the values in MainModel by FbnTableController
tableRows = mainModel.getTableRows();
}
//following mathods are implemented
public int getRowCount(){}
public int getColumnCount(){}
public int getValueAt(){}
}
/* FbnClient class is also there, which creates instance of FbnTableModel, and passed to constructor of JTable, which then passed to JScrollPane*/
Any help is welcome. I have tried to implement MVC pattern by using two classes, but I was not able to differentiate the functinality of Model and view and controller in two classes.
Pratibha
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public FbnTable(MainModel model){
colNames = mainModel.getColumnNames();
//Problem is here: Here it gives NullpointerException, colNames gets null value even after setting the values in MainModel by FbnTableController
tableRows = mainModel.getTableRows();
}
Check out the parameter and what is that variable's name, and what is the name that is calling getColumnNames(). Do you notice something strange?
Mark
 
Pratibha Gayake
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry, the original code is as per following: (It was my typing mistake)
public FbnTable(MainModel model){
columnNames = mainModel.getColumnNames();
//Problem is here: Here it gives NullpointerException, colNames gets null value even after setting the values in MainModel by FbnTableController
rows = mainModel.getTableRows();
}
I am really sorry for this.
Pratibha
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still say the same thing. Is the variable named mainModel in the parameter list? No, it is called model
So if you try to call any methods on mainModel, and there is no reference variable with that name then there is no class to call methods on
Mark
 
Pratibha Gayake
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I got the answer.
Thanks
Pratibha
 
Dave McCarthy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for not being able to give you a reply. I've been on a job for a few days and wasn't near a computer with a net connection.
Nice to be back at this.


Dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic