This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Variable CONSTANT may not have been initialized.

 
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this compiler error really an error, or just a friendly "watch out!" warning?
When I go ahead and run the program it seems to be OK.
My declaration looks like this:
final ClassName CONSTANT ;

CONSTANT is a public constant of a certain class. Maybe there's a right way to do this?
Thanks ,
Pauline
 
Sheriff
Posts: 9099
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess I don't understand why you need to declare CONSTANT if it is a constant of another class.
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marilyn,
"Why" is basically: I'm kind of fumbling around playing with this... so I don't really know even if I need to do this
CONSTANT is in a class I've imported, but when I use it without declaring it I get this compiler error: Undefined variable: CONSTANT
I'm hoping this class is the right one for Grains (but don't know that for sure yet). Working with objects of this class, it seemed easier to use this constant than to create a new object with this value.
??
Pauline

[This message has been edited by Pauline McNamara (edited June 15, 2001).]
 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What version of the JDK are you running? I do not believe that particular CONSTANT was defined in the class prior to JDK 1.2. I know it wasn't defined in JDK 1.1.8.
 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using CONSTANT just by saying CONSTANT or by specifying ClassName.CONSTANT?
------------------
I'm a soldier in the NetScape Wars...
Joel
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, thanks everyone for the quick help!
Richard, I'm using 1.1.8, the macintosh-fans-who-didn't-crank-up-to-OSX-version of the JDK. Hmmm, could I already have an excuse for a hardware upgrade?
Joel, I've only said CONSTANT not ClassName.CONSTANT. Will try that right away.
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm, got a new compiler message when I used ClassName.CONSTANT:
Variable CONSTANT in class java.xxx.Xxxx not accessible from class Grains.
Strange?
 
Marilyn de Queiroz
Sheriff
Posts: 9099
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like this?
<pre>
import java.xxxx.Xxxxx

class Grains
{

public static void main( String[] args )
{
Xxxxx identifier = Xxxxx.CONSTANT ;
}

}
<pre>

[This message has been edited by Marilyn deQueiroz (edited June 15, 2001).]
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Marilyn.
Just tried that syntax. (Is this how I should use any class' constant, by assigning it to an identifier?)
Anyway, at this line
Xxxxx identifier = Xxxxx.CONSTANT ;
I got that compiler error again:
Variable CONSTANT in class java.xxxx.Xxxxx not accessible from class Grains.
Could this have to do with Richard's observation that I'm only using JDK 1.1.8?
Thanks again
Pauline
ps Using this constant isn't actually essential in order to pass in my next attempt, however I'd stumbled upon a neat way to express the total grains and was hoping to use it - but it involves basic arithmetic with this constant value...

[This message has been edited by Pauline McNamara (edited June 16, 2001).]
 
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pauline, even if you dont get it to work hold on to it. We can discuss it in the "private" forum. Might be fun.
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good Morning Johannes,
I'm looking forward to getting a peek at that solutions forum. Maybe I should submit the attempt without this particular problem (other problems may lurk within!) to try to get a little closer to graduating.

Pauline
 
Johannes de Jong
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good morning to you too.
Actually very quite there. I've been to busy with other things to really push it. Will be glad to have you there with your inquiring mind
You sometimes learn more by submitting something "wrong". But it does create more work for Marilyn though
[This message has been edited by Johannes de Jong (edited June 16, 2001).]
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just checked tha API, you were right on Richard, the constant I'm after is only since 1.2.
So much for my fumblings, will submit my original approach without compiler problems.
As for syntax (for the future), should I just use Marilyn's example as a model?
Thanks everybody,
Pauline
[This message has been edited by Pauline McNamara (edited June 16, 2001).]
 
Johannes de Jong
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still would like to see you code though.
 
Marilyn de Queiroz
Sheriff
Posts: 9099
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should upgrade or you won't be able to do the OOP assignments.
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering when I'd get hung up on that...
...Excellent, that's just the justification I needed to take the plunge! I've already been drooling, uh, I mean, looking around at the latest options.
And the solution to Grains (cool!) cleared up my questions above.
Thanks Pauline
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!