问题描述
我正在使用Google地图精简版模式版本,在该版本中,我在联想K50a40 上绘制多边形线条和标记,我接收到以下错误:
**非致命异常:java.lang.ArrayIndexOutOfBoundsException:length = 42;索引= 42 **
at maps.ah.ka(未知来源:4000)
at maps.ah.ka(未知来源)
at maps.ah.ka(未知来源)
at maps.ah.ia(未知来源)
at maps.ah.d.onDraw(未知来源)
at android.view.View.draw(View.java:16457)
at android.view.View.buildDrawingCacheImpl(View.java:15722)
at android.view.View.buildDrawingCache(View.java:15576)
at android.view.View.draw(View .java:16204)
at android.view.ViewGroup.drawChild(ViewGroup.java:3746)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3536)
at android。 view.View.updateDisplayListIfDirty(View.java:15402)
在android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
在android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dis patchGetDisplayList(ViewGroup.java:3710)
在android.view.View.updateDisplayListIfDirty(View.java:15361)
在android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
在android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java :3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view。 ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayL istIfDirty(View.java:15361)
在android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
在android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
在android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java :3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view。 ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
在android.view.View.updateDisplayListIfDirty(View.java:15361)
在android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
。在android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
在android.view.View.updateDisplayListIfDirty(View.java:15361)
在android.view.ViewGroup.recreateChildDisplayLi (ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
在android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java :15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view。 View.updateDisplayListIfDirty(View.java:15361)
在android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
在android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(Vie wGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android .view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
在android.view.View.updateDisplayListIfDirty(View.java:15361)
在android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730 )
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup。 recreateChildDisplayList(ViewGroup.java:3730)
在android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
在android.view.View.updateDisplayListIfDirty(View.java:15361)
在android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:286)
在android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:292)
在android.view.ThreadedRenderer .draw(ThreadedRenderer.java:327)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:3024)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2828)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2440)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1325)
at android.view.ViewRootImpl $ TraversalRunnable.run(在Android.view.Choreographer
$ CallbackRecord.run(Choreographer.java:912)
at android.view.Choreographer.doCallbacks(Choreographer.java:714)
在android.view.Choreographer.doFrame(Choreographer.java:649)
在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:898)
在android.os.Handler.handleCallback(处理程序.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android。 app.ActivityThread.main(ActivityThread.java:5769)在java.lang.reflect处
。 Method.invoke(Method.java)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:789)
在com.android.internal.os.ZygoteInit.main( ZygoteInit.java:679)
以下是我在Google地图上绘制路线的逻辑
public static void drawRouteIntoMap(List< ;?扩展MapHelper>位置,最终谷歌地图GoogleMap,最终布尔removeMarker){
/ * List< MapHelper> position = new ArrayList< MapHelper>();
for(int i = lastPosition; i< maps.size(); i ++){
position.add(maps.get(i)); ();
} * /
if(position.size()> 0&& Validator.isNotNull(googleMap)){
// googleMap.clear();
最终列表< ;?扩展MapHelper> tempList = new ArrayList<>(position);
if(tempList.size()!= pointList.size()){
tempList.removeAll(pointList);
}
列出< PolylineOptions> polylineOptionses = new ArrayList< PolylineOptions>();
PolylineOptions选项= null;
布尔lastPause = null;
for(MapHelper map:tempList){
if(map.isPause()){
if(Validator.isNull(lastPause)||!lastPause){
option = new PolylineOptions()。width(5).color(Color.rgb(255,0,155))。geodesic(true);
polylineOptionses.add(option);
}
option.add(new LatLng(map.getLatitude(),map.getLongitude()));
} else {
if(Validator.isNull(lastPause)|| lastPause){
option = new PolylineOptions()。width(5).color(Color.rgb(0,179, 253))测地(真);
polylineOptionses.add(option);
}
option.add(new LatLng(map.getLatitude(),map.getLongitude()));
}
lastPause = map.isPause();
(PolylineOptions选项:polylineOptionses){
googleMap.addPolyline(options);
}
if(Validator.isNotNull(option)){
List< LatLng> points = option.getPoints();
final LatLngBounds.Builder mapBounds = new LatLngBounds.Builder(); (LatLng latLng:points)
{
mapBounds.include(latLng);
googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback(){
@Override
public void onMapLoaded(){
if(removeMarker){
if(Validator.isNotNull(endMarker)){
startMarker.remove();
endMarker.remove();
}
}
LatLng startPoint = new LatLng(tempList.get(0).getLatitude(),tempList.get(0).getLongitude());
Marker marker1 = googleMap.addMarker(new MarkerOptions()。position(startPoint).title(开始)的图标(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
经纬度端点=新经纬度(tempList.get(tempList.size() - 1).getLatitude(),tempList.get(tempList。 size() - 1).getLongitude());
Marker marker2 = googleMap.addMarker(new MarkerOptions()。position(endPoint).title(finish)。icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(mapBounds.build(),10));
googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(mapBounds.build(),10));
googleMap.moveCamera(CameraUpdateFactory.zoomOut());
startMarker = marker1;
endMarker = marker2;
}
});
pointList = position;
$ / code>
我在其中进行测试的设备只出现在联想k50a40型号中,我无法弄清楚实际原因是否有任何帮助是appriciated。
为什么会崩溃?
通过查看异常,一切都表明您正在遍历Array(或List)。
检查主要消息
弄清楚后面的事情会更棘手,主要是因为我们没有关于代码的任何信息:
at maps.ah.ka(未知来源:4000)
at maps.ah.ka(未知来源)
at maps.ah.ka(Unknown Source)
at maps.ah.ia(Unknown Source)
为什么它可以在其他设备上工作?
不同的Android设备有不同的软件基础和硬件基础(取决于制造它们的公司)可能会在某些时候看到不同的行为。
因此,即使其他设备可以处理非致命异常,Lenovo K50a40似乎也无法做到。或者它甚至可能是联想系统设计不当,也无法知道。
你很难做到。我的解决方案可帮助您找到路径:
- 将控制台日志放在任何地方都可以。
- 删除尽可能多的逻辑,并一点一点地添加,直到找到破坏它的东西。
- 删除
forEach
在java中,并强制一个正常的for(int i = 0; i< maps.size(); i ++)
code> i 。
代码评估
这就是说,有些东西我从代码中得不到。
if(map.isPause ()){
if(Validator.isNull(lastPause)||!lastPause){
option = new PolylineOptions()。width(5).color(Color.rgb(255,0,155) ).geodesic(真);
polylineOptionses.add(option);
}
option.add(new LatLng(map.getLatitude(),map.getLongitude()));
} else {
if(Validator.isNull(lastPause)|| lastPause){
option = new PolylineOptions()。width(5).color(Color.rgb(0,179, 253))测地(真);
polylineOptionses.add(option);
}
option.add(new LatLng(map.getLatitude(),map.getLongitude()));
$ / code>
如果 map.isPause() code>返回true并且
Validator.isNull(lastPause)|| !lastPause
返回false?
如果我理解正确,您将运行 option.add(new LatLng .getLatitude(),map.getLongitude()));
。
这将导致一个空异常。
您可以给一些上下文而不是 pointList
变量吗? hr>
我知道这可能不是您所希望的,但我仍然希望这会有所帮助。
I am using google map lite mode version in which i am drawing poly lines and markers on Lenovo K50a40 I m receiving following error
**Non-fatal Exception: java.lang.ArrayIndexOutOfBoundsException: length=42; index=42**
at maps.ah.k.a(Unknown Source:4000)
at maps.ah.k.a(Unknown Source)
at maps.ah.k.a(Unknown Source)
at maps.ah.i.a(Unknown Source)
at maps.ah.d.onDraw(Unknown Source)
at android.view.View.draw(View.java:16457)
at android.view.View.buildDrawingCacheImpl(View.java:15722)
at android.view.View.buildDrawingCache(View.java:15576)
at android.view.View.draw(View.java:16204)
at android.view.ViewGroup.drawChild(ViewGroup.java:3746)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3536)
at android.view.View.updateDisplayListIfDirty(View.java:15402)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3730)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3710)
at android.view.View.updateDisplayListIfDirty(View.java:15361)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:286)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:292)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:327)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:3024)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2828)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2440)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1325)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6741)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:912)
at android.view.Choreographer.doCallbacks(Choreographer.java:714)
at android.view.Choreographer.doFrame(Choreographer.java:649)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:898)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5769)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
and below is my logic for drawing route on google map
public static void drawRouteIntoMap(List<? extends MapHelper> position, final GoogleMap googleMap , final boolean removeMarker) {
/*List<MapHelper> position = new ArrayList<MapHelper>();
for (int i = lastPosition; i < maps.size(); i++) {
position.add(maps.get(i));
}*/
if (position.size() > 0 && Validator.isNotNull(googleMap)) {
// googleMap.clear();
final List<? extends MapHelper> tempList=new ArrayList<>(position);
if(tempList.size()!=pointList.size()) {
tempList.removeAll(pointList);
}
List<PolylineOptions> polylineOptionses = new ArrayList<PolylineOptions>();
PolylineOptions option = null;
Boolean lastPause = null;
for (MapHelper map : tempList) {
if (map.isPause()) {
if (Validator.isNull(lastPause) || !lastPause) {
option = new PolylineOptions().width(5).color(Color.rgb(255, 0, 155)).geodesic(true);
polylineOptionses.add(option);
}
option.add(new LatLng(map.getLatitude(), map.getLongitude()));
} else {
if (Validator.isNull(lastPause) || lastPause) {
option = new PolylineOptions().width(5).color(Color.rgb(0, 179, 253)).geodesic(true);
polylineOptionses.add(option);
}
option.add(new LatLng(map.getLatitude(), map.getLongitude()));
}
lastPause = map.isPause();
}
for (PolylineOptions options : polylineOptionses) {
googleMap.addPolyline(options);
}
if(Validator.isNotNull(option)) {
List<LatLng> points = option.getPoints();
final LatLngBounds.Builder mapBounds = new LatLngBounds.Builder();
for (LatLng latLng : points) {
mapBounds.include(latLng);
}
googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
if(removeMarker) {
if (Validator.isNotNull(endMarker)) {
startMarker.remove();
endMarker.remove();
}
}
LatLng startPoint = new LatLng(tempList.get(0).getLatitude(), tempList.get(0).getLongitude());
Marker marker1=googleMap.addMarker(new MarkerOptions().position(startPoint).title("start").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
LatLng endPoint = new LatLng(tempList.get(tempList.size() - 1).getLatitude(), tempList.get(tempList.size() - 1).getLongitude());
Marker marker2=googleMap.addMarker(new MarkerOptions().position(endPoint).title("finish").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(mapBounds.build(), 10));
googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(mapBounds.build(), 10));
googleMap.moveCamera(CameraUpdateFactory.zoomOut());
startMarker=marker1;
endMarker=marker2;
}
});
pointList = position;
}
}
}
the devices in which i performed testing among them it only occurs only in lenovo k50a40 model i am not able to figure it out actual cause any help is appriciated.
Why does it crash?
By looking at the exception, everything indicates that you are traversing an Array (or List) incorrectly.
Check the main message
Figuring out what goes after, is more tricky, mainly because we have no information about the code whatsoever:
at maps.ah.k.a(Unknown Source:4000)
at maps.ah.k.a(Unknown Source)
at maps.ah.k.a(Unknown Source)
at maps.ah.i.a(Unknown Source)
Why does it work on some other devices?
Different Android devices have different software bases and hardware bases (depending on the company that manufactures them) and so one can expect to see different behaviors at some points.
Thus, even though other devices can deal with the non-fatal exception, Lenovo K50a40 seems not be able to. Or it may even be a Lenovo system incorrectly designed, there is no way to know.
What would I do?
There is little you can do.My solution to help you find the path is to:
- Place console logs everywhere you can.
- Remove as much logic as possible and add little by little until you find something that breaks it.
- Remove the
forEach
in java and force a regularfor (int i = 0; i < maps.size(); i++)
loop everywhere I can, and monitor for the values ofi
.
Code evaluation
This said, there are some things I don't quite get from your code.
if (map.isPause()) {
if (Validator.isNull(lastPause) || !lastPause) {
option = new PolylineOptions().width(5).color(Color.rgb(255, 0, 155)).geodesic(true);
polylineOptionses.add(option);
}
option.add(new LatLng(map.getLatitude(), map.getLongitude()));
} else {
if (Validator.isNull(lastPause) || lastPause) {
option = new PolylineOptions().width(5).color(Color.rgb(0, 179, 253)).geodesic(true);
polylineOptionses.add(option);
}
option.add(new LatLng(map.getLatitude(), map.getLongitude()));
}
What happens if map.isPause()
returns true and Validator.isNull(lastPause) || !lastPause
returns false?
If I understand correctly, you will be running option.add(new LatLng(map.getLatitude(), map.getLongitude()));
on a null object.
This will cause a Null Exception.
Can you give some context not pointList
variable?
I know this is probably not what you were hoping for, but I still hope it will help.
这篇关于Android折线上的ArrayIndexOutOfBounds绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!