Results 1 to 10 of 10
- 07-16-2011, 09:18 PM #1
Class names are only accepted if annotation processing is explicitly requested
The above error, which is documented here, is being displayed, when I try to compile the source code (see below), using Textpad 5.4.2, and, the command line.
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\Jon\workspace\JavaDev\corejava7\v2\v2ch6\ TableSortTest
>prompt $g
>dir
Volume in drive C has no label.
Volume Serial Number is D80F-8634
Directory of C:\Documents and Settings\Jon\workspace\JavaDev\corejava7\v2\v2ch6
\TableSortTest
16/07/2011 20:55 <DIR> .
16/07/2011 20:55 <DIR> ..
16/07/2011 20:55 194 SortFilterModel$1.class
16/07/2011 20:55 1,214 SortFilterModel$Row.class
16/07/2011 20:55 1,760 SortFilterModel.class
16/07/2011 20:55 953 TableSortFrame$1.class
16/07/2011 20:55 2,276 TableSortFrame.class
16/07/2011 20:55 424 TableSortTest.class
07/09/2004 06:36 4,685 TableSortTest.java
7 File(s) 11,506 bytes
2 Dir(s) 32,871,919,616 bytes free
>javac -Xlint TableSortTest
error: Class names, 'TableSortTest', are only accepted if annotation processing
is explicitly requested
1 error
>java -version
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)
Sourced from Core Java Vol 2 (7th Ed), Chp 6.PHP Code:/** @version 1.01 2004-08-22 @author Cay Horstmann */ import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.table.*; /** This program demonstrates how to sort a table column. Double-click on a table columm's header to sort it. */ public class TableSortTest { public static void main(String[] args) { JFrame frame = new TableSortFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } /** This frame contains a table of planet data. */ class TableSortFrame extends JFrame { public TableSortFrame() { setTitle("TableSortTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // set up table model and interpose sorter DefaultTableModel model = new DefaultTableModel(cells, columnNames); final SortFilterModel sorter = new SortFilterModel(model); // show table final JTable table = new JTable(sorter); add(new JScrollPane(table), BorderLayout.CENTER); // set up double click handler for column headers table.getTableHeader().addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent event) { // check for double click if (event.getClickCount() < 2) return; // find column of click and int tableColumn = table.columnAtPoint(event.getPoint()); // translate to table model index and sort int modelColumn = table.convertColumnIndexToModel(tableColumn); sorter.sort(modelColumn); } }); } private Object[][] cells = { { "Mercury", 2440.0, 0, false, Color.yellow }, { "Venus", 6052.0, 0, false, Color.yellow }, { "Earth", 6378.0, 1, false, Color.blue }, { "Mars", 3397.0, 2, false, Color.red }, { "Jupiter", 71492.0, 16, true, Color.orange }, { "Saturn", 60268.0, 18, true, Color.orange }, { "Uranus", 25559.0, 17, true, Color.blue }, { "Neptune", 24766.0, 8, true, Color.blue }, { "Pluto", 1137.0, 1, false, Color.black } }; private String[] columnNames = { "Planet", "Radius", "Moons", "Gaseous", "Color" }; private static final int DEFAULT_WIDTH = 400; private static final int DEFAULT_HEIGHT = 200; } /** This table model takes an existing table model and produces a new model that sorts the rows so that the entries in a given column are sorted. */ class SortFilterModel extends AbstractTableModel { /** Constructs a sort filter model. @param m the table model whose rows should be sorted */ public SortFilterModel(TableModel m) { model = m; rows = new Row[model.getRowCount()]; for (int i = 0; i < rows.length; i++) { rows[i] = new Row(); rows[i].index = i; } } /** Sorts the rows. @param c the column that should become sorted */ public void sort(int c) { sortColumn = c; Arrays.sort(rows); fireTableDataChanged(); } // Compute the moved row for the three methods that access model elements public Object getValueAt(int r, int c) { return model.getValueAt(rows[r].index, c); } public boolean isCellEditable(int r, int c) { return model.isCellEditable(rows[r].index, c); } public void setValueAt(Object aValue, int r, int c) { model.setValueAt(aValue, rows[r].index, c); } // delegate all remaining methods to the model public int getRowCount() { return model.getRowCount(); } public int getColumnCount() { return model.getColumnCount(); } public String getColumnName(int c) { return model.getColumnName(c); } public Class getColumnClass(int c) { return model.getColumnClass(c); } /** This inner class holds the index of the model row Rows are compared by looking at the model row entries in the sort column. */ private class Row implements Comparable<Row> { public int index; public int compareTo(Row other) { Object a = model.getValueAt(index, sortColumn); Object b = model.getValueAt(other.index, sortColumn); if (a instanceof Comparable) return ((Comparable) a).compareTo(b); else return a.toString().compareTo(b.toString()); } } private TableModel model; private int sortColumn; private Row[] rows; }
- 07-16-2011, 09:23 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,603
- Blog Entries
- 7
- Rep Power
- 17
From the link you supplied yourself: "If you receive this error, you forgot to include the .java suffix when compiling the program. Remember, the command is javac HelloWorldApp.java not javac HelloWorldApp."
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 07-16-2011, 09:44 PM #3
It's not the case. Having pasted and compiled the errors in Eclipse 3.6.2, now the only issue is this:
Error: Type safety: The method compareTo(Object) belongs to the raw type Comparable. References to generic type Comparable<T> should be parameterizedPHP Code:public int compareTo(Row other) { Object a = model.getValueAt(index, sortColumn); Object b = model.getValueAt(other.index, sortColumn); if (a instanceof Comparable) return ((Comparable) a).compareTo(b); else return a.toString().compareTo(b.toString()); } }
>javac -Xlint TableSortTest.java
TableSortTest.java:30: warning: [serial] serializable class TableSortFrame has n
o definition of serialVersionUID
class TableSortFrame extends JFrame
^
TableSortTest.java:149: warning: [unchecked] unchecked call to compareTo(T) as a
member of the raw type java.lang.Comparable
return ((Comparable) a).compareTo(b);
^
TableSortTest.java:90: warning: [serial] serializable class SortFilterModel has
no definition of serialVersionUID
class SortFilterModel extends AbstractTableModel
^
3 warnings
I think that the problem is that TableModel requires a compareTo() method, otherwise it won't compile, do you agree?Last edited by jon80; 07-16-2011 at 09:54 PM.
- 07-17-2011, 07:38 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,603
- Blog Entries
- 7
- Rep Power
- 17
Yes it is; quoting you:
You don't compile *.java files like that. (see the documentation).Java Code:>javac -Xlint TableSortTest
kind regards,
Jos
ps. Your other isssue has nothing to do with this issue; also read the documentation for the Comparable<T> interface and read some tutorials on generics.When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 07-17-2011, 07:51 AM #5
Well you should read my reply, there was an update.
- 07-17-2011, 07:57 AM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,603
- Blog Entries
- 7
- Rep Power
- 17
I did read your reply, including the update; if you want help you should read the replies posted by others (here: me). Your first issue was explained in the documentation for which you supplied a link yourself; for your second issue see my previous reply.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 07-17-2011, 07:57 AM #7
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
I would guess Jos has read your replies. And I have.
You say got an error from javac. It was pointed out that the javac usage was incorrect and the error always occurs when you use a class name argument in this context. It's a bit of a mystery what you mean by "it's not the case". Clearly it is the case: you use a class name argument in the (incorrect) way you posted and you will get the error you reported.
- 07-17-2011, 08:18 AM #8
It might have been the case originally but it's not the only problem, because there was a subsequent reply to my original post. Excuse.
- 07-17-2011, 08:25 AM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,603
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 07-17-2011, 09:24 AM #10
Similar Threads
-
Define accepted values from terminal to array
By KAS in forum New To JavaReplies: 6Last Post: 04-02-2011, 06:05 PM -
Annotation Processing in Eclipse Ganymede
By mcfrog in forum EclipseReplies: 2Last Post: 07-23-2009, 06:42 AM -
Compile time Annotation Processing - Maven build problem
By Milesy in forum Advanced JavaReplies: 0Last Post: 07-09-2009, 11:11 AM -
getting the method and the class names (as argument, String varialbe)
By itaipee in forum New To JavaReplies: 4Last Post: 03-03-2009, 09:39 AM -
Class Reflection: Finding super class names
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:12 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks