0
How to call an array relation in the menu
i have two classes, one is related to the another one with an array ( departments []) and i have a menu class, so i need to call a method on each element of the array (deparments[1].giveName();) but it keeps returning errors about the privacy of the relation and stuff like that, any help?
11 Respostas
+ 1
You should be able to use a method to retrive the data and make the call. If not, a friend class relationship could fix it. If you still can't get it link the code or a small subset to show the relationships, data, and methods involved. I'm sure someone will be able to help you from there.
The default protection of data is private to other classes so accessing another's data is something you should try to avoid.
+ 1
Thanks man. You really saved my life
0
Post your code
0
there are 4 .javas of code, is there an email where i can send them to you?
0
Sorry I don't know Spanish, but from what I can see:
You're missing the following imports in Menu.java:
import modelo.Municipio;
import modelo.Departamento;
and:
CensoDepto in the main method isn't initialized before attempting to use it here:
CensoDepto.MunicipiosPertenecientes[0] = new Municipio(elNombre, laPoblacion, cHombres, cMujeres, cAdultosM, Epromedio, Ipromedio);
I initialized it like:
Departamento CensoDepto = new Departamento("Department");
After altering the above the code runs.
You can change several of your access modifiers to private and package private too:
in Pias.java Departamento[] can be private,
in Municipio.java all of the //ATRIBUTOS can be private,
and your methods look like they can be package private (no modifier),
in Departamento.java it looks like your methods can also be package private.
0
i initialized it and now i have this error on the last lane: cannot find symbol
symbol: variable MunicipiosD
location: variable censoDepto of type Departamento
0
Did you add the import to Menu.java?
import modelo.Municpio;
0
yes
0
Ok, If it is literally spelled MunicipiosD in error and this is not a typo in the post then you most likely have accidentally added the D to the end of the name on the specified line. Also with censoDepto it should have a capital C like CensoDepto according to the rest of your code. Check through those lines and make sure that you didn't accidentally change their spelling and/or capitalization etc.
0
Here's the edited version if that helps:
https://drive.google.com/open?id=0B0WvpWZkJHGcLWtFa3Zwc01tTWc