Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

JTable ClassCastException : Help please

Thread view: 
suresh.gn@gmail.com - 11 Jul 2006 08:25 GMT
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?
Oliver Wong - 11 Jul 2006 21:59 GMT
> Dear Java experts,
>
[quoted text clipped - 37 lines]
> 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
suresh.gn@gmail.com - 12 Jul 2006 06:15 GMT
data3 is Object[][] data3 = { {1,1,1},
                                        {1,1,1},
                                        {1,1,1}
                                      };
> > Dear Java experts,
> >
[quoted text clipped - 42 lines]
>
>     - Oliver
Oliver Wong - 12 Jul 2006 15:39 GMT
[post re-ordered]

>> > ((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
[quoted text clipped - 5 lines]
>                                         {1,1,1}
>                                       };

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

   - Oliver


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.