Making an object public
Hi. I create an object of a type in my main method as follow:
Ciudades ciudades =new Ciudades();/
then, I tried to use this object in another class and I create a method that receives this object
publicvoid setCiudades(Ciudades ciudades){
lasCiudades = ciudades
this.getCiudades(lasCiudades);
}
I create a method with a return to make the object available to all the methods in the class
public Ciudades getCiudades(Ciudades lasCiudades){
return lasCiudades;
}
finally, when I want to use this object in a method in this class, I got a null pointer exception...
Somebody knows what is the reason of this?
regards...
[975 byte] By [
karma1234a] at [2007-11-27 4:09:32]

Thanks for your answer, but It dont works. I磎 going to explain my problem in other way:
I create some objects in my main method. I have a master class that controls all the functions of the program, is like a controller. In the main method I create an object controller and within its parameters I send the other objects that I created. For example:
Genetista genetista = new Genetista();//AUXILIAR OBJECTS
Cartografo cartografo = new Cartografo();//AUXILIAR OBJECTS
Dibujante dibujante = new Dibujante();//AUXILIAR OBJECTS
then I create the controlador object
Controlador controlador = new Controlador(genetista,cartografo,dibujante);
I the controlador class, I have some atributes that have the Genetista, Cartografo, Dibujante types, for example:
private Genetista elGenetista;
private Cartografo elCartografo;
private Dibujante elDibujante;
Then in the constructor of the controlador class, I initialize this objects:
public Controlador(Genetista genetista, Cartografo cartografo, Dibujante dibujante){
elGenetista = genetista;
elCartografo = cartografo;
elDibujante = dibujante;
}
Then, when I try to use this objects they have null value, so I can not do nothing. For example I use:
elGenetista.getValues()
And I got a null pointer exception, because the elGenetista object does not exist, but I have created it in the constructor.
Any idea?
Kind regards.
> Thanks for your answer, but It dont works. I磎 going
> to explain my problem in other way:
>
Well I'll be honest with you. There's really no point.
The code you posted originally is very much rubbish. My edits will help you fix a problem but I am not surprised that there are more.
You should go and read the tutorials. Failing that you should be posting your relevent code. Posting more explanations is a just a waste of everyone's time, including yours.
Thanks, I solved the problem.
The problem is that I was using two different objects, in my main method I create something like Controlador controlador = new Controlador(x,y), I was supposed to use this object, but I was using another one that was Controlador controlador = new Controlador(). They are different objects, so they do not have the same information, that was the reason of my problem.
Thanks everybody and regards.