Results 1 to 10 of 10
  1. #1
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    213
    Rep Power
    9

    Default 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)

    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;
    }
    Sourced from Core Java Vol 2 (7th Ed), Chp 6.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,271
    Blog Entries
    7
    Rep Power
    24

    Default

    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,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  3. #3
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    213
    Rep Power
    9

    Default

    It's not the case. Having pasted and compiled the errors in Eclipse 3.6.2, now the only issue is this:
    PHP 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());
       }
    }
    Error: Type safety: The method compareTo(Object) belongs to the raw type Comparable. References to generic type Comparable<T> should be parameterized

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

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,271
    Blog Entries
    7
    Rep Power
    24

    Default

    Quote Originally Posted by jon80 View Post
    It's not the case.
    Yes it is; quoting you:

    Java Code:
    >javac -Xlint TableSortTest
    You don't compile *.java files like that. (see the documentation).

    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.
    The only person who got everything done by Friday was Robinson Crusoe.

  5. #5
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    213
    Rep Power
    9

    Default

    Well you should read my reply, there was an update.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,271
    Blog Entries
    7
    Rep Power
    24

    Default

    Quote Originally Posted by jon80 View Post
    Well you should read my reply, there was an update.
    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,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  7. #7
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,712
    Rep Power
    14

    Default

    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.

  8. #8
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    213
    Rep Power
    9

    Default

    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.

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,271
    Blog Entries
    7
    Rep Power
    24

    Default

    Quote Originally Posted by jon80 View Post
    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.
    I really don't understand what's happening here: I answered your original question and I answered your other question(s) in reply #4. Do you see different replies from the text I see?

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  10. #10
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    213
    Rep Power
    9

Similar Threads

  1. Define accepted values from terminal to array
    By KAS in forum New To Java
    Replies: 6
    Last Post: 04-02-2011, 06:05 PM
  2. Annotation Processing in Eclipse Ganymede
    By mcfrog in forum Eclipse
    Replies: 2
    Last Post: 07-23-2009, 06:42 AM
  3. Replies: 0
    Last Post: 07-09-2009, 11:11 AM
  4. Replies: 4
    Last Post: 03-03-2009, 10:39 AM
  5. Class Reflection: Finding super class names
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 08:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •