Getter/Setter Problem in Java?

Posted by Praveen Chandrasekaran on Stack Overflow See other posts from Stack Overflow or by Praveen Chandrasekaran
Published on 2010-06-17T10:57:17Z Indexed on 2010/06/17 11:03 UTC
Read the original article Hit count: 149

Filed under:
|

Hi Folks,

I want to pass the String value between the classes both are same package. so i created the the classs like the code:

public class Map_Delegate {
String myLatitude;
String myLongitude;
String myName;
private String TAG = "Map_Delegate";

public String getMyName() {

    return this.myName;
}

public void setMyName(String value) {
    Log.v(TAG, value);
    this.myName = value;
}

public String getMyLatitude() {

    return this.myLatitude;
}

public void setMyLatitude(String value) {
    Log.v(TAG, value);
    this.myLatitude = value;
}

public String getMyLongitude() {

    return this.myLongitude;
}

public void setMyLongitude(String value) {
    Log.v(TAG, value);
    this.myLongitude = value;
}
}

But it can't pass the value. I done like this code to set the value:

Map_Delegate map = new Map_Delegate();
map.setMyName(first_name_temp + " " + last_name_temp);
map.setMyLatitude(homeLatitude_temp);
map.setMyLongitude(homeLongitude_temp);

code to get the value:

   Map_Delegate map = new Map_Delegate();
   name_val = getMyName();
   lat_val = getMyLatitude();
   long_val = getMyLongitude();

Why get the Null value can you Guess? All classes in the same package and public .AnyIdea?

© Stack Overflow or respective owner

Related posts about java

Related posts about beginner