Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Java NetBeans:JTable: illegal forward reference

  1. Aug 26, 2016 #1
    I have created a table using Netbeans. Then i have used properties->model option for table to insert row and to give column names using NetBeans frame work. Now i am trying to create an instance variable of DefaultTableModel in the application class:

    DefaultTableModel model = (DefaultTableModel) figTable.getModel();

    But i am getting following error:
    "illegal forward reference": Move initializer to constructor.

    Some body please guide me.

  2. jcsd
  3. Aug 27, 2016 #2


    Staff: Mentor

  4. Aug 27, 2016 #3
    I checked that link. I tried according to that but still i am getting the same thing:
    public class FigureInheritanceJFrame extends javax.swing.JFrame {

    final DefaultTableModel model;
    model = (DefaultTableModel) figTable.getModel();

    My error is :

    Cannot find symbol

    Symbol: class model

    <identifier > expected

    Illegal forward reference

    Some body please guide me.

  5. Aug 27, 2016 #4


    Staff: Mentor

    I could be wrong, but based on your error message, you are using model before it has been initialized. See if this gets rid of your error:
    Code (Java):
    final DefaultTableModel model = null;
    model = (DefaultTableModel) figTable.getModel();
  6. Aug 27, 2016 #5
    Thanks for your attention. I tried this:

    Code (Java):
    final DefaultTableModel model=null;
        model = (DefaultTableModel) figTable.getModel();
    but still i am getting the same error.

    Some body please guide me.

  7. Aug 27, 2016 #6
    JFrame is not a subclass or super class of JTable, both of which are subclasses of awt.Window and swing.JComponent respectively whereas DefaultTableModel is one of java.swing.table.AbstractTableModel.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted