Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JTable ClassCastException : Help please

Reply
Thread Tools

JTable ClassCastException : Help please

 
 
suresh.gn@gmail.com
Guest
Posts: n/a
 
      07-11-2006
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[i][j] =
((Integer)data3[i][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?

 
Reply With Quote
 
 
 
 
Oliver Wong
Guest
Posts: n/a
 
      07-11-2006

<> wrote in message
news: ps.com...
> 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[i][j] =
> ((Integer)data3[i][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

 
Reply With Quote
 
 
 
 
suresh.gn@gmail.com
Guest
Posts: n/a
 
      07-12-2006
data3 is Object[][] data3 = { {1,1,1},
{1,1,1},
{1,1,1}
};
Oliver Wong wrote:
> <> wrote in message
> news: ps.com...
> > 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[i][j] =
> > ((Integer)data3[i][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


 
Reply With Quote
 
Oliver Wong
Guest
Posts: n/a
 
      07-12-2006
[post re-ordered]

<> wrote in message
news: oups.com...
> Oliver Wong wrote:
>> <> wrote in message
>> news: ps.com...
>> > ((Integer)data3[i][j]).intValue();

[...]
>>
>> 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

>
> data3 is Object[][] data3 = { {1,1,1},
> {1,1,1},
> {1,1,1}
> };


Why don't you declare data3 as being an int[][] and not casting to
Integer?

- Oliver

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with JTable ... ClassCastException Luiss Java 4 05-07-2012 03:43 AM
Putting a JTable inside a JTable cell? Tivo Escobar Java 1 04-12-2007 11:09 AM
How to move data from a CSV file to a JTable, and from a JTable to a CSV file ? Tintin92 Java 1 02-14-2007 06:51 PM
Runtime ClassCastException when assigning clone of Area subclass Richard A. DeVenezia Java 2 01-08-2004 01:06 PM
ClassCastException and ClassLoaders Luther Baker Java 3 09-10-2003 02:56 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57