Now I have a strange problem. I have FusedLocationApi code.check it.I'm mentioning only related codes :
public class MainActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{
GoogleApiClient mGoogleApiClient;
Location mLastLocation;
@Override
protected void onStart() {
mGoogleApiClient.connect();
super.onStart();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
double latitude = mLastLocation.getLatitude();
double longitude = mLastLocation.getLongitude();
}
@Override
protected void onStop() {
mGoogleApiClient.disconnect();
super.onStop();
}
}
Now the problem is,this code is working perfectly for this activity.But when I'm writing the same code for other activity of the same project,mLastLocation
is returning null and I am getting a java.lang.NullPointerException.
only difference for that class is that there I'm implementing OnMapReadyCallback
also.Does it make any difference?
I've read all the Q&A on this topic but not getting any help. What's the mistake from my side?