• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

might not have been initialized

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I'm back, lol.
Thank you all for the great advise, has help alot.

Have all 3 programs written with only 2 Errors.

Can someone help explain the following to me?

-Called Compiler C:\PROGRA~1\Java\JDK15~1.0_0\bin\javac.exe-
-Target File: G:\NEW9~1\CheckingAccountsTest.java-
G:\NEW9~1\CheckingAccountsTest.java:98: variable currentAcccount might not have been initialized
sumOfBeginningBalances += currentAcccount.getBalance();
^
G:\NEW9~1\CheckingAccountsTest.java:130: variable currentAcccount might not have been initialized
sumOfBeginningBalances += currentAcccount.getBalance();
^
2 errors

-Finished-


 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you create an instance of a class, if you don't explicitly assign values to the instance variables, they are given default values.

However, this is not true with local variables. You have to make sure you initialize local variables before any statement that tries to use their value.
 
mike hew
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So our you saying something like this,

CheckingAccount currentAcccount = new CheckingAccount(arguments); ?
 
Ranch Hand
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.

I think that the problem is that the variable in question is a local variable and it is initialized inside of a conditional. I think that you need to initialize it in the main block of code for that method.

-- Kaydell
 
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, local variables MUST be explicitly initialised before they're first read.
If you initialise them in conditional statements structured in a way that the compiler cannot ascertain one will always be executed, it will generate that error.
Either restructure your conditionals so the compiler can ascertain your local will always be initialised (if possible) or initialise it explicitly to something at declaration (most people use null for that).
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic