java.lang.ClassCastException(Android-Studio)

Viewed 25

I am getting this error in my app and my app crashes.

java.lang.ClassCastException: android.location.Location cannot be cast to com.example.locationtest.LocationData

LocationData class

package com.example.locationtest;

import android.location.Location;


public class LocationData extends Location {

private String address;

public LocationData(Location l) {
    super(l);
}

public LocationData(Location l, String address) {
    super(l);
    this.address = address;
}

public String getAddress() {
    return address;
}

public void setAddress(String address) {
    this.address = address;
}

}

intent.PutExtra(MainActivity):

Intent i = new Intent(this, GoogleMapsActivity.class);
if (locationData != null){
    i.putExtra("locationData", locationData);
}
startActivity(i);

the part that caused the error(GoogleMapsActivity):

if (getIntent().hasExtra("locationData")){
    castError: => locationData = getIntent().getParcelableExtra("locationData");
}

Can you help me find where I went wrong?

0 Answers
Related