I am retrieving values from database. I initialized a variable outside the loop. I am using while loop to move one record after other to last using ResultSet object.next(). Inside the while I am assigning the record value to the variable initialized outside while. But It shows variable might not have been initialized error inside while and in succeeding code wherever that variable is used.
If I move them as class variable outside the method too i got error "Non Static variable cannot be initialized from static context".
stephy1
0
Light Poster
Recommended Answers
Jump to PostThen you may have declared the variable outside the loop, but you didn't initialise (i.e. define) it. IOW if you do
String bogus; while (true) { if (bogus.equals("Whatever")) { break; } }
(as a contrived example)
you will get that compiler message, whereas with
All 4 Replies
masijade
1,351
Industrious Poster
Team Colleague
Featured Poster
stephy1
0
Light Poster
stephy1
0
Light Poster
VernonDozier
2,218
Posting Expert
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.