IllegalArgumentException:宽度和高度必须 > Google MapView 中缩小期间为 0

发布于 2024-08-28 19:00:40 字数 4046 浏览 5 评论 0原文

我正在尝试在 Activity 的 oncreateMethod 中放大 Google MapView。 每次我尝试通过 mapController 缩放地图时,都会收到 IllegalArgumentException:

04-15 10:16:51.012: ERROR/AndroidRuntime(528): java.lang.RuntimeException: Unable to start activity ComponentInfo{android.client/android.client.ui.showstores.StoreMap}: java.lang.IllegalArgumentException: width and height must be > 0

如果我调用 MapController。遗憾的是,我正在使用的 ZoomIn 函数不带任何参数。

我调用缩放函数的 onCreateMethod 看起来像这样:

    mapView = (MapView) findViewById(R.id.map);
    mapView.setBuiltInZoomControls(true);
    MapController mapController = mapView.getController();
    mapController.zoomIn();

我在这里有点不知所措,因为我没有做任何特别的事情。

整个堆栈跟踪是:

04-15 10:16:51.012: ERROR/AndroidRuntime(528): java.lang.RuntimeException: Unable to start activity ComponentInfo{android.client/android.client.ui.showstores.StoreMap}: java.lang.IllegalArgumentException: width and height must be > 0
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.app.ActivityThread.access$2100(ActivityThread.java:116)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.os.Looper.loop(Looper.java:123)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.app.ActivityThread.main(ActivityThread.java:4203)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at java.lang.reflect.Method.invokeNative(Native Method)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at java.lang.reflect.Method.invoke(Method.java:521)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at dalvik.system.NativeStart.main(Native Method)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): Caused by: java.lang.IllegalArgumentException: width and height must be > 0
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.graphics.Bitmap.nativeCreate(Native Method)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at com.google.android.maps.ZoomHelper.createSnapshot(ZoomHelper.java:305)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at com.google.android.maps.ZoomHelper.doZoom(ZoomHelper.java:137)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at com.google.android.maps.ZoomHelper.doZoom(ZoomHelper.java:126)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at com.google.android.maps.MapView.doZoom(MapView.java:1459)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at com.google.android.maps.MapView.doZoom(MapView.java:1468)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at com.google.android.maps.MapController.zoomIn(MapController.java:427)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.client.ui.showstores.StoreMap.onCreate(StoreMap.java:58)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     ... 11 more

I'm trying to zoom in on a Google MapView on step in the oncreateMethod of my Activity.
Everytime I try to zoom the map via the mapController I get an IllegalArgumentException:

04-15 10:16:51.012: ERROR/AndroidRuntime(528): java.lang.RuntimeException: Unable to start activity ComponentInfo{android.client/android.client.ui.showstores.StoreMap}: java.lang.IllegalArgumentException: width and height must be > 0

This Exception is thrown if I call the zoomOut or zoomIn function of MapController. Sadly the zoomIn function I'm using does not take any arguments.

The onCreateMethod where I'm calling the zoom functions looks like this:

    mapView = (MapView) findViewById(R.id.map);
    mapView.setBuiltInZoomControls(true);
    MapController mapController = mapView.getController();
    mapController.zoomIn();

I'm a little bit at loss here because I'm doing nothing special.

The whole stacktrace is:

04-15 10:16:51.012: ERROR/AndroidRuntime(528): java.lang.RuntimeException: Unable to start activity ComponentInfo{android.client/android.client.ui.showstores.StoreMap}: java.lang.IllegalArgumentException: width and height must be > 0
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.app.ActivityThread.access$2100(ActivityThread.java:116)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.os.Looper.loop(Looper.java:123)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.app.ActivityThread.main(ActivityThread.java:4203)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at java.lang.reflect.Method.invokeNative(Native Method)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at java.lang.reflect.Method.invoke(Method.java:521)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at dalvik.system.NativeStart.main(Native Method)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): Caused by: java.lang.IllegalArgumentException: width and height must be > 0
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.graphics.Bitmap.nativeCreate(Native Method)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at com.google.android.maps.ZoomHelper.createSnapshot(ZoomHelper.java:305)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at com.google.android.maps.ZoomHelper.doZoom(ZoomHelper.java:137)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at com.google.android.maps.ZoomHelper.doZoom(ZoomHelper.java:126)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at com.google.android.maps.MapView.doZoom(MapView.java:1459)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at com.google.android.maps.MapView.doZoom(MapView.java:1468)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at com.google.android.maps.MapController.zoomIn(MapController.java:427)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.client.ui.showstores.StoreMap.onCreate(StoreMap.java:58)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
04-15 10:16:51.012: ERROR/AndroidRuntime(528):     ... 11 more

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心病无药医 2024-09-04 19:00:40

我找到了解决这种情况的方法。

   int zoomSteps = 2;

   int currentLatitudeSpan = mMapView.getLatitudeSpan();
   int currentLongitudeSpan = mMapView.getLongitudeSpan();

   int zoomedLatitudeSpan = 2 * zoomSteps * currentLatitudeSpan;
   int zoomedLongitudeSpan = 2 * zoomSteps * currentLongitudeSpan;

   mMapController.zoomToSpan(zoomedLatitudeSpan, zoomedLongitudeSpan);'

此片段将地图缩放两倍

I found a workaround for that situation.

   int zoomSteps = 2;

   int currentLatitudeSpan = mMapView.getLatitudeSpan();
   int currentLongitudeSpan = mMapView.getLongitudeSpan();

   int zoomedLatitudeSpan = 2 * zoomSteps * currentLatitudeSpan;
   int zoomedLongitudeSpan = 2 * zoomSteps * currentLongitudeSpan;

   mMapController.zoomToSpan(zoomedLatitudeSpan, zoomedLongitudeSpan);'

This snippet zooms the map twice

落花浅忆 2024-09-04 19:00:40

Android 直到稍后才会设置视图的宽度和高度,因此在 onCreate 中它将为 0。我认为视图在名为“onLayoutChanged”或类似的方法中指定它们的大小,也许您可​​以覆盖它并在那里进行缩放。

Android doesn't set the width and height of views until later, so it'll be 0 in onCreate. I think views specify their sizes in a method called "onLayoutChanged" or something similar, maybe you can override it and do the zoom there.

伪装你 2024-09-04 19:00:40

您可能会尝试在 onWindowFocusChanged(boolean hasFocus) 而不是 onCreate 或 onResume 中调用缩放方法。

You might try to call the zoom methods in onWindowFocusChanged(boolean hasFocus) instead of onCreate or onResume.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文