Can't understand syntax error with Java 6.0

Discussion in 'Java' started by Wes Harrison, Jun 28, 2006.

  1. Wes Harrison

    Wes Harrison Guest

    I am getting a syntax error in my Java code that I cannot understand and
    hope you can help me. It's with Java 6.0 and TableRowSorter. The line of
    code is:

    table.setRowSorter(new TableRowSorter(tableModel));

    where table is a JTable and tableModel is an implementation of an
    AbstractTableModel. The errors I get are:

    MyTable.java:204: warning: [unchecked] unchecked call to TableRowSorter(M)
    as a member of the raw type javax.swing.table.TableRowSorter
    table.setRowSorter(new TableRowSorter(tableModel));
    ^
    MyTable.java:204: warning: [unchecked] unchecked conversion
    found : javax.swing.table.TableRowSorter
    required: javax.swing.RowSorter<? extends javax.swing.table.TableModel>
    table.setRowSorter(new TableRowSorter(tableModel));

    What do they mean exactly and how do I fix the problem?

    Thanks,

    Wes
    Wes Harrison, Jun 28, 2006
    #1
    1. Advertising

  2. Wes Harrison

    Danno Guest

    Wes Harrison wrote:
    > I am getting a syntax error in my Java code that I cannot understand and
    > hope you can help me. It's with Java 6.0 and TableRowSorter. The line of
    > code is:
    >
    > table.setRowSorter(new TableRowSorter(tableModel));
    >
    > where table is a JTable and tableModel is an implementation of an
    > AbstractTableModel. The errors I get are:
    >
    > MyTable.java:204: warning: [unchecked] unchecked call to TableRowSorter(M)
    > as a member of the raw type javax.swing.table.TableRowSorter
    > table.setRowSorter(new TableRowSorter(tableModel));
    > ^
    > MyTable.java:204: warning: [unchecked] unchecked conversion
    > found : javax.swing.table.TableRowSorter
    > required: javax.swing.RowSorter<? extends javax.swing.table.TableModel>
    > table.setRowSorter(new TableRowSorter(tableModel));
    >
    > What do they mean exactly and how do I fix the problem?
    >
    > Thanks,
    >
    > Wes


    Show us what tableModel looks like ;)
    Danno, Jun 29, 2006
    #2
    1. Advertising

  3. Wes Harrison

    Bjorn Abelli Guest

    "Wes Harrison" wrote...

    > I am getting a syntax error in my Java code that I cannot
    > understand and hope you can help me.


    It's not a syntax error, not even an error. It's a compiler warning.

    Read the lines again, and you'll see that it's a warning that something's
    "unchecked".

    warning: [unchecked]

    > What do they mean exactly and how do I fix the problem?


    It means that you can get your application more typesafe by using generics,
    i.e. to provide in the source code what type of TableModel your
    TableRowSorter is supposed to handle.

    When using that option, it means that it will do further checks in the
    compilation that you won't use any other TableModel than your specific
    implementation of it.

    You don't *have* to do anything, as it's not a "problem". If it compiled
    with only those warnings, the compilation still got through.

    /// Bjorn A





    Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
    Bjorn Abelli, Jun 29, 2006
    #3
  4. Wes Harrison

    horahora.geo

    Joined:
    Jan 23, 2008
    Messages:
    1
    It means that you can get your application more typesafe by using generics,
    i.e. to provide in the source code what type of TableModel your
    TableRowSorter is supposed to handle.

    eg

    if you are using the DefaultTableModel.

    Specify as such
    TableRowSorter<DefaultTableModel> sorter = new TableRowSorter<DefaultTableModel>(tableModel);
    horahora.geo, Jan 23, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sean Hammond

    Anyone understand this syntax error?

    Sean Hammond, Dec 2, 2006, in forum: Python
    Replies:
    2
    Views:
    273
    Peter Otten
    Dec 3, 2006
  2. Chris Saunders

    Don't understand syntax error

    Chris Saunders, May 16, 2005, in forum: C Programming
    Replies:
    9
    Views:
    457
    CBFalconer
    May 17, 2005
  3. Stef Mientki
    Replies:
    0
    Views:
    561
    Stef Mientki
    Oct 20, 2008
  4. Terry Reedy
    Replies:
    0
    Views:
    679
    Terry Reedy
    Oct 20, 2008
  5. Antoon Pardon

    I don't understand this syntax error

    Antoon Pardon, Jan 19, 2009, in forum: Python
    Replies:
    1
    Views:
    248
    Peter Otten
    Jan 19, 2009
Loading...

Share This Page