JTable ClassCastException : Help please

S

suresh.gn

Dear Java experts,

I have a JTable problem here.
Problem description: I have to display a default table(3X3) when the
application launches for the first time. Then user should able to
modify the table and my application should able to read the changed
values in this table. Please have a look at the below code.

Table3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){

for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
try{
t3[j] =
((Integer)data3[j]).intValue();
}catch(ClassCastException cce){}
}
}
table3.getModel().addTableModelListener(new
TableModelListener(){
public void tableChanged(TableModelEvent e) {
int row = e.getFirstRow();
int column = e.getColumn();
TableModel model = (TableModel)e.getSource();
String columnName = model.getColumnName(column);
Object data3 = model.getValueAt(row, column);
t3[row][column] = new
Integer((String)data3).intValue();
}
});
}
});

here table3 is a JTable
Table3 is the radio button used to select that matrix
data3 is an Object[][] with column names for JTable
t3 is the default matrix used and modified by the user.

When I use this code, my application throwing ClassCastException
because of converting data3 to t3. Can any body help me?
 
O

Oliver Wong

Dear Java experts,

I have a JTable problem here.
Problem description: I have to display a default table(3X3) when the
application launches for the first time. Then user should able to
modify the table and my application should able to read the changed
values in this table. Please have a look at the below code.

Table3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){

for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
try{
t3[j] =
((Integer)data3[j]).intValue();
}catch(ClassCastException cce){}
}
}
table3.getModel().addTableModelListener(new
TableModelListener(){
public void tableChanged(TableModelEvent e) {
int row = e.getFirstRow();
int column = e.getColumn();
TableModel model = (TableModel)e.getSource();
String columnName = model.getColumnName(column);
Object data3 = model.getValueAt(row, column);
t3[row][column] = new
Integer((String)data3).intValue();
}
});
}
});

here table3 is a JTable
Table3 is the radio button used to select that matrix
data3 is an Object[][] with column names for JTable
t3 is the default matrix used and modified by the user.

When I use this code, my application throwing ClassCastException
because of converting data3 to t3. Can any body help me?


The data3 on the 8th line of code that you posted never gets declared
anywhere. Please post an SSCCE: http://mindprod.com/jgloss/sscce.html

- Oliver
 
S

suresh.gn

data3 is Object[][] data3 = { {1,1,1},
{1,1,1},
{1,1,1}
};
Oliver said:
Dear Java experts,

I have a JTable problem here.
Problem description: I have to display a default table(3X3) when the
application launches for the first time. Then user should able to
modify the table and my application should able to read the changed
values in this table. Please have a look at the below code.

Table3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){

for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
try{
t3[j] =
((Integer)data3[j]).intValue();
}catch(ClassCastException cce){}
}
}
table3.getModel().addTableModelListener(new
TableModelListener(){
public void tableChanged(TableModelEvent e) {
int row = e.getFirstRow();
int column = e.getColumn();
TableModel model = (TableModel)e.getSource();
String columnName = model.getColumnName(column);
Object data3 = model.getValueAt(row, column);
t3[row][column] = new
Integer((String)data3).intValue();
}
});
}
});

here table3 is a JTable
Table3 is the radio button used to select that matrix
data3 is an Object[][] with column names for JTable
t3 is the default matrix used and modified by the user.

When I use this code, my application throwing ClassCastException
because of converting data3 to t3. Can any body help me?


The data3 on the 8th line of code that you posted never gets declared
anywhere. Please post an SSCCE: http://mindprod.com/jgloss/sscce.html

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top