不能投射到 com.google.android.gms.location.LocationListener(我已经实现



当我尝试运行我的应用程序时,应用程序崩溃了,并且在日志猫中看到此错误。

--------- beginning of crash
09-07 22:46:49.571 3479-3479/com.example.www.mytaxiapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.www.mytaxiapp, PID: 3479
java.lang.ClassCastException: com.example.www.mytaxiapp.Welcome cannot be cast to com.google.android.gms.location.LocationListener
at com.example.www.mytaxiapp.Welcome.startLocationUpdates(Welcome.java:272)
at com.example.www.mytaxiapp.Welcome.onConnected(Welcome.java:308)

这是我的进口

import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.os.Handler;
import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.widget.Toast;
import com.firebase.geofire.GeoFire;
import com.firebase.geofire.GeoLocation;
import com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.zzal;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

这是我的方法,错误从这里来了,有人可以帮助我吗? 我正在尝试修复它几个小时 搜索互联网

public class Welcome extends FragmentActivity implements OnMapReadyCallback,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
LocationListener
{
private void startLocationUpdates() {
if(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED  )
{
return;
}
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,mLocationRequest, (com.google.android.gms.location.LocationListener) this);
}

请检查您导入的库。您导入了无效的位置侦听器。 您必须导入正确的位置Listner,

请更改

import android.location.LocationListener;

com.google.android.gms.location.LocationListener

这将解决您的问题。

谢谢。

相关内容

  • 没有找到相关文章