NetBeans:JTable: illegal forward reference

  • Java
  • Thread starter zak100
  • Start date
  • Tags
    Reference
In summary, the conversation discusses an error that the person is getting when trying to create an instance variable of DefaultTableModel in their application class. They are trying to reference a variable before it has been defined or initialized, and have tried using a null value but are still getting the same error. They are seeking guidance on how to fix the error.
  • #1
zak100
462
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
  • #3
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.
 
  • #4
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.
 
  • #5
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.
 
  • #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.
 

1. What is a "NetBeans:JTable: illegal forward reference" error?

A "NetBeans:JTable: illegal forward reference" error is an error that occurs when the NetBeans IDE is unable to resolve a reference to a variable, method, or class. This means that the code is trying to access something that has not yet been declared or defined.

2. Why does the "NetBeans:JTable: illegal forward reference" error occur?

This error typically occurs when code is written in a way that creates a circular dependency, where one class or method depends on another that also depends on the first. This creates a conflict and the NetBeans IDE is unable to resolve the reference.

3. How can I fix the "NetBeans:JTable: illegal forward reference" error?

To fix this error, you will need to review your code and remove any circular dependencies. This may involve restructuring your code or using different design patterns. You may also need to declare or define the referenced item before it is used.

4. Can I prevent the "NetBeans:JTable: illegal forward reference" error from occurring?

Yes, you can prevent this error by carefully planning your code structure and avoiding circular dependencies. It is also helpful to declare or define variables, methods, and classes before they are used.

5. Are there any resources available for troubleshooting "NetBeans:JTable: illegal forward reference" errors?

Yes, there are many resources available online for troubleshooting this error. The NetBeans community forums and documentation are great places to start. You can also consult with other developers or seek out tutorials on proper coding practices to avoid this error.

Similar threads

  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
2
Views
4K
  • Programming and Computer Science
Replies
4
Views
330
  • Programming and Computer Science
Replies
9
Views
2K
  • Programming and Computer Science
Replies
3
Views
4K
  • Programming and Computer Science
Replies
26
Views
6K
  • Programming and Computer Science
Replies
19
Views
1K
  • Programming and Computer Science
Replies
7
Views
425
  • Programming and Computer Science
Replies
4
Views
988
  • Programming and Computer Science
Replies
8
Views
850
Back
Top