NetBeans:JTable: illegal forward reference

  • Context: Java 
  • Thread starter Thread starter zak100
  • Start date Start date
  • Tags Tags
    Reference
Click For Summary

Discussion Overview

The discussion centers around an error encountered while using NetBeans to create a JTable and its associated DefaultTableModel. Participants are exploring the cause of the "illegal forward reference" error when trying to initialize the model variable in the application class.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant describes the error encountered when trying to create an instance variable of DefaultTableModel, indicating that it is due to referencing a variable before it is defined or initialized.
  • Another participant suggests that the error arises from using the model variable before it has been initialized, and provides a link to a related Stack Overflow post.
  • A participant attempts to implement a suggested solution but continues to receive an error regarding the model variable, indicating a "Cannot find symbol" error and reiterating the illegal forward reference issue.
  • Further attempts to initialize the model variable with a null assignment are also met with the same error, prompting a request for additional guidance.
  • One participant notes the relationship between JFrame, JTable, and DefaultTableModel, suggesting that the class hierarchy may be relevant to the issue at hand.

Areas of Agreement / Disagreement

Participants express uncertainty about the correct initialization of the model variable and whether the class hierarchy is contributing to the problem. There is no consensus on a definitive solution, as multiple attempts to resolve the issue have not succeeded.

Contextual Notes

Participants have not fully resolved the underlying assumptions regarding variable initialization and class relationships, which may affect the understanding of the error encountered.

zak100
Messages
462
Reaction score
11
Hi,
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.

Zulfi.
 
Technology news on Phys.org
Hi.
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 referenceSome body please guide me.

Zulfi.
 
zak100 said:
Hi.
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();
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:
Java:
final DefaultTableModel model = null;
model = (DefaultTableModel) figTable.getModel();
zak100 said:
My error is :

Cannot find symbol

Symbol: class model

<identifier > expected

Illegal forward referenceSome body please guide me.

Zulfi.
 
Hi,
Thanks for your attention. I tried this:

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

Some body please guide me.

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

Similar threads

Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 3 ·
Replies
3
Views
7K
  • · Replies 26 ·
Replies
26
Views
8K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
4
Views
4K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 19 ·
Replies
19
Views
2K