To be honest i am really struggling with Java, i am trying to access an array from another class. I believe i have created the array in this code
public class aff_array {
String name;
public static void main (String[] args) {
int z = 3; //total no of affirmations
int x = 1;
aff_array[] afz = new aff_array[z]; //dim
while ( x < z ) {
afz[x] = new aff_array(); // create objects for array
x = x + 1;
}
afz[1].name = "i am the best";
afz[2].name = "you are the rest";
}
but i am really having trouble trying to figure out how i access afz[1].name for example, from another class. This is probably basic but i am really struggling..
afzvariable is a local variable - it's declared inmain, and unless you pass the value to another method (or copy it to a field somewhere) nothing else will be able to see it. I suggest you read docs.oracle.com/javase/tutorial/java/nutsandbolts/…public String name... but you should probably do some Java learning instead of solving this particular problem...