I have an activity ShowList
where I have some edittext
fields and buttons
.
I have a button
"get location
" which gets the current location
with GPS
.
The ShowList activity
(which works fine , I can get the location
) :
public class ShowList extends Activity implements OnClickListener{
GPSTracker gps; //i use GPSTracker to get the location (it is not an activity)
.........
case R.id.getlocation:
// create class object
gps = new GPSTracker(ShowList.this);
// check if GPS enabled
if(gps.canGetLocation()){
double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
}else{
...
}
I have a custom adapter:
public class myAdapter extends BaseAdapter{
ShowList locationclass=new ShowList();
.....
TextView Location = (TextView) convertView.findViewById(R.id.text_location);
String lat=Double.toString(locationclass.gps.getLatitude());
String lo=Double.toString(locationclass.gps.getLongitude());
String coordinates="Lat: " + lat + " Long: " + lo;
Location.setText(coordinates);
I receive the nullpointer
in "String lat...".
So, how can I pass the location
from ShowList activity
to adapter
?