This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with arrays/class

 
tan kian
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i got a Cannot resolve symbol error. what i am trying to do is create a number of accounts(depending on user input) and do id verification. is it possible for me to get back the input tt i got in createacc and use it in check?
[JAM -- added [CODE] and [/CODE] tags]
[ April 17, 2004: Message edited by: Joel McNary ]
 
Raj Chila
Ranch Hand
Posts: 128
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check where you have declared the Acc[] acct = new Acc[i]; it is with in the create() method...make acct global...and it should work
 
tan kian
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Acc
{
//assume constructor etc is done
Acc[] acct = new Acc[i];
public int createacc()
{
System.out.println("How many accounts?");
i = cs.readInt();
Acc[] acct = new Acc[i];
do u mean like this? i get an array index out of bounds error now(during run time), in:
if(getid.compareTo(acct[j].id) == 0)
 
tan kian
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Acc
{
Acc[] acct;
public int createacc()
{
for (j=0;j<=count;j++)
{
acct[j].bal = (acct[j].bal)*1.5;
}
return i;
}
public int checkid(int i)
{ //error here
//code omitted
}
}
i dont know why, but i got this Return statement not initialised/assigned error on my code. can someone help?
 
Raj Chila
Ranch Hand
Posts: 128
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi tian,
you took my statement literally, what I meant was to declare the acct globally and initialize the array in the create()..this way the visibility of the acct will be to all the methods in the class. earlier you declared and initialized within the create() method so you got cannot resolve symbol error.
I am reproducing the code here with changes...just go through it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic