Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TextView globalCoordinates = null;
- private GoogleApiClient mGoogleApiClient;
- private Location mLastLocation;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- globalCoordinates = (TextView)findViewById(R.id.textView);
- mGoogleApiClient = new GoogleApiClient.Builder(this)
- .addConnectionCallbacks((GoogleApiClient.ConnectionCallbacks) getApplicationContext())
- .addOnConnectionFailedListener((GoogleApiClient.OnConnectionFailedListener)getApplicationContext())
- .addApi(LocationServices.API)
- .build();
- }
- @Override
- public void onConnected(Bundle bundle) {
- mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
- if (mLastLocation != null) {
- globalCoordinates.setText("Latitude: " + String.valueOf(mLastLocation.getLatitude())+ ""
- + "Longitude: " + String.valueOf(mLastLocation.getLongitude()));
- }
- }
- java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.atifarain.module01/com.example.atifarain.module01.MainActivity}: java.lang.ClassCastException: android.app.Application cannot be cast to com.google.android.gms.common.api.GoogleApiClient$ConnectionCallbacks
- at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2200)
- at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
- at android.app.ActivityThread.access$800(ActivityThread.java:139)
- at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
- at android.os.Handler.dispatchMessage(Handler.java:102)
- at android.os.Looper.loop(Looper.java:136)
- at android.app.ActivityThread.main(ActivityThread.java:5105)
- at java.lang.reflect.Method.invokeNative(Native Method)
- at java.lang.reflect.Method.invoke(Method.java:515)
- at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
- at dalvik.system.NativeStart.main(Native Method)
- Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to com.google.android.gms.common.api.GoogleApiClient$ConnectionCallbacks
- at com.example.atifarain.module01.MainActivity.onCreate(MainActivity.java:30)
- at android.app.Activity.performCreate(Activity.java:5275)
- at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
- at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement