Java NetBeans:JTable: illegal forward reference

  • Thread starter Thread starter zak100
  • Start date Start date
  • Tags Tags
    Reference
Click For Summary
The discussion revolves around an issue with initializing a DefaultTableModel in a Java application using NetBeans. The user encounters an "illegal forward reference" error when trying to assign the model variable before it is properly initialized. Despite attempts to resolve the issue by setting the model to null initially, the user continues to face errors related to variable initialization and symbol recognition. A key point raised is the distinction between JFrame and JTable, highlighting that JFrame is not a subclass of JTable, which may be relevant to understanding the context of the model's usage. The conversation emphasizes the importance of proper variable initialization and the relationship between different components in the Swing framework.
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.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

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