• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have this:

The compiler says that rows and columnNames must be declared static. Why this?
Thank advance.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please supply the full details of the error message.
 
Andrei Mura
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic