java.lang.IllegalStateException:不在Google地图的主线程中 [英] java.lang.IllegalStateException: Not on the main thread Google Maps
本文介绍了java.lang.IllegalStateException:不在Google地图的主线程中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Android应用代码从云端消息传递平台接收数据时,出现上述错误, java.lang.IllegalStateException:不在主线程上
在maps.wca(未知源)
在maps.yFa(未知源)
在maps.ad. ub(未知来源)
在vo.onTransact(:com.google.android.gms.DynamiteModulesB:92)
在android.os.Binder.transact(Binder.java:380)
at com.google.android.gms.maps.internal.IGoogleMapDelegate $ zza $ zza.animateCamera(Unknown Source)
at com.google.android.gms.maps.GoogleMap.animateCamera(Unknown Source)
at com.pabba.mtracker.tracking.view.TrackingActivity.onLocationReceived(TrackingActivity.java:54)
以下是我的演示者(我正在为我的android应用使用MVP模式)在从云消息服务接收到位置消息时调用的代码。
@Override
public void onLocationReceived(LatLng latLng){
Log.i(TAG,latLng.toString());
mGoogleMap.addPolyline(new PolylineOptions()。add(latLng));
mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder()。target(latLng)
.zoom(13).build()));
}
这个错误发生在addPolyLine函数调用中。
请告诉我可以做些什么来解决它。
解决方案
您必须在UIThread中运行以下代码:
activity.runOnUIThread(new Runnable(){
public void run(){
mGoogleMap.addPolyline新的PolylineOptions().add(latLng));
mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder().target(latLng)
.zoom(13).build()));
}
});
I am getting the above error when my Android app code receives data from a cloud messaging platform and I try to put that data on the map -
java.lang.IllegalStateException: Not on the main thread
at maps.w.c.a(Unknown Source)
at maps.y.F.a(Unknown Source)
at maps.ad.u.b(Unknown Source)
at vo.onTransact(:com.google.android.gms.DynamiteModulesB:92)
at android.os.Binder.transact(Binder.java:380)
at com.google.android.gms.maps.internal.IGoogleMapDelegate$zza$zza.animateCamera(Unknown Source)
at com.google.android.gms.maps.GoogleMap.animateCamera(Unknown Source)
at com.pabba.mtracker.tracking.view.TrackingActivity.onLocationReceived(TrackingActivity.java:54)
The following is the code that is called by my presenter (I am using MVP Pattern for my android app) when it receives a Location message from the Cloud Messaging service.
@Override
public void onLocationReceived(LatLng latLng) {
Log.i(TAG, latLng.toString());
mGoogleMap.addPolyline(new PolylineOptions().add(latLng));
mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder().target(latLng)
.zoom(13).build()));
}
And the error is occurring in the addPolyLine function call. Please tell me what can be done to resolve it.
解决方案
you must run this code in the UIThread:
activity.runOnUIThread(new Runnable(){
public void run(){
mGoogleMap.addPolyline(new PolylineOptions().add(latLng));
mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder().target(latLng)
.zoom(13).build()));
}
});
这篇关于java.lang.IllegalStateException:不在Google地图的主线程中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文