无法转换为com.google.android.gms.location.LocationListener
我的主要问题是,在通过登录后不会潜入第二个活动应用程序崩溃,有些人帮我识别问题所在它来自我的布局还是......! !
locgat
E/UncaughtException: java.lang.ClassCastException: com.logo.tm.androiddriverapp.Welcome cannot be cast to com.google.android.gms.location.LocationListener
at com.logo.tm.androiddriverapp.Welcome.startLocationUpdate(Welcome.java:532)
at com.logo.tm.androiddriverapp.Welcome.onConnected(Welcome.java:571)
at com.google.android.gms.common.internal.zzae.zzk(Unknown Source)
at com.google.android.gms.common.api.internal.zzba.zzj(Unknown Source)
at com.google.android.gms.common.api.internal.zzao.zzaie(Unknown Source)
at com.google.android.gms.common.api.internal.zzao.onConnected(Unknown Source)
at com.google.android.gms.common.api.internal.zzbi.onConnected(Unknown Source)
at com.google.android.gms.common.api.internal.zzt.onConnected(Unknown Source)
at com.google.android.gms.common.internal.zzac.onConnected(Unknown Source)
at com.google.android.gms.common.internal.zzn.zzakr(Unknown Source)
at com.google.android.gms.common.internal.zze.zzw(Unknown Source)
at com.google.android.gms.common.internal.zzi.zzaks(Unknown Source)
at com.google.android.gms.common.internal.zzh.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5631)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
D/FA: Logging event (FE): app_exception(_ae), Bundle[{firebase_event_origin(_o)=crash, firebase_screen_class(_sc)=Welcome, firebase_screen_id(_si)=-5990294920665317261,
这是欢迎的布局代码,不知道是否有一些异常的事情:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/layout_panel"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<fragment
android:id="@+id/place_autocomplete_fragment"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="5"/>
</LinearLayout>
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/layout_panel"
tools:context="com.logo.tm.androidapp.Welcome" />
<android.support.v7.widget.CardView
app:cardElevation="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<LinearLayout
android:orientation="horizontal"
android:weightSum="10"
android:layout_margin="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch
android:id="@+id/location_switch"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content"
app:icon_release="@drawable/ic_location_off"
app:icon_press="@drawable/ic_location_on"
app:base_release_color="@color/baseReleaseColor"
app:base_press_color="@color/basePressColor"
app:ball_release_color="@color/ballReleaseColor"
app:ball_press_color="@android:color/white" />
<Button
android:id="@+id/btn_find_user"
android:layout_weight="7"
android:text="FIND RIDERS"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
java welcome class 抱歉,我的身体上没有更多的空间,这是代码的链接
https://drive.google.com/file/d/1v6Frd1fHB_m65z2Sg74a9qERS2Llmiyu/view?usp=sharing
答案 0 :(得分:0)
替换为:LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, (com.google.android.gms.location.LocationListener) this);
用这个:
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient,this);
并替换它:
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,mLocationRequest, (com.google.android.gms.location.LocationListener) this);
用这个:
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,mLocationRequest, this);
我的意思是删除(com.google.android.gms.location.LocationListener)
,因为你已经实现了LocationListener,你不需要强制转换。
答案 1 :(得分:0)
promlem在您导入的库中位于类的顶部,它应该是
android.location.LocationListener;
不导入{{1}}替换此内容。