Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes Help with arrays/class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with arrays/class" Watch "Help with arrays/class" New topic
Author

Help with arrays/class

tan kian
Ranch Hand

Joined: Apr 09, 2004
Posts: 40

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

Joined: Mar 18, 2004
Posts: 128

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

Joined: Apr 09, 2004
Posts: 40
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

Joined: Apr 09, 2004
Posts: 40
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

Joined: Mar 18, 2004
Posts: 128

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with arrays/class
 
Similar Threads
Stumped, need inspiration.
question about treemaps
All of URLy Bird 1.1.3 about Junit test
adding to an existing array
nx:All of URLy Bird 1.1.3 about multiple thread test