Forums Register Login

why variables from super(....); must be declared static?

+Pie Number of slices to send: Send
I have this:

The compiler says that rows and columnNames must be declared static. Why this?
Thank advance.
+Pie Number of slices to send: Send
Please supply the full details of the error message.
+Pie Number of slices to send: Send
I use Eclipse IDE. This is a compiler error, so the error is:

Multiple markers at this line
- Cannot refer to an instance field columnNames while explicitly invoking a
constructor
- Cannot refer to an instance field rows while explicitly invoking a constructor

But i think that i've understand. Probably i can't use instance variables because the first line executed is super(....). So is needed that the fields to be static.
what is your opinion?
+Pie Number of slices to send: Send
You are introducing a circular dependency. That is why there is a problem.

You are trying to set the value of those two fields from the value of those fields.
+Pie Number of slices to send: Send
because when call to super is encountered inside constructor yet the instance is not created for that class....so thats is the reason you cant use any instance variable iinside super but since static variable does not exist with respect any instance so they can be used.
+Pie Number of slices to send: Send
Sandeep is right. When a constructor is created, the following occurs (in order):
1) the call to super()
2) initialization of fields and execution of initializer blocks
3) the actual body of the constructor

Since columnNames and rows don't get initialized until step 2 they will have no value at step 1.

But why do you need to store the column names and data in the JTable? It's already stored in the model, and the JTable can simply retrieve it from it.
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1287 times.
Similar Threads
creating JTable using data from .txt file
Swing--JTable in JInternalFrame
Add Row with AbstractTableModel
JTable, Table Models, Vectors & Objects : Confused
JTable problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 20:03:43.