Can't understand syntax error with Java 6.0

W

Wes Harrison

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
 
D

Danno

Wes said:
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 ;)
 
B

Bjorn Abelli

...
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
 
Joined
Jan 23, 2008
Messages
1
Reaction score
0
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);
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top