gpt4 book ai didi

android - 强制关闭 mapController?

转载 作者:行者123 更新时间:2023-11-29 22:24:49 25 4
gpt4 key购买 nike

我有一个奇怪的问题。我想在 map 上显示某个位置。问题是有时一切正常,但有时我会强制关闭并且在 DDMS 中我得到:06-03 18:24:14.171:错误/AndroidRuntime(2228):在 com.google.android.maps.MapController.setCenter(MapController.java:345)看来问题出在线上:mapView.getController().setCenter(pt)。我能理解,为什么有时一切都很好,有时却不行。

这是我的代码:

package com.ShoppingList.Shops;


import java.io.IOException;
import java.util.List;
import java.util.Locale;

import com.ShoppingList.R;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

import java.util.ArrayList;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class ShowMap extends MapActivity {
private MapView mapView;
MapController mc;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.showmap);

mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapView.setClickable(true);

Drawable marker=getResources().getDrawable(R.drawable.pushpin);
marker.setBounds(0, 0, marker.getIntrinsicWidth(),
marker.getIntrinsicHeight());

InterestingLocations funPlaces = new InterestingLocations(marker);
mapView.getOverlays().add(funPlaces);
GeoPoint pt = funPlaces.getCenter(); // get the first-ranked point
mapView.getController().setCenter(pt);
mapView.getController().setZoom(15);

}
@Override
protected boolean isLocationDisplayed() {
return false;
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
class InterestingLocations extends ItemizedOverlay {
private List<OverlayItem> locations = new ArrayList<OverlayItem>();
private Drawable marker;
String adresa;
public InterestingLocations(Drawable marker)
{
super(marker);
this.marker=marker;
// create locations of interest
Bundle bundle = getIntent().getExtras();
adresa = bundle.getString("adress");

Geocoder geoCoder = new Geocoder(ShowMap.this, Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocationName(adresa, 5);
String add = "";
if (addresses.size() > 0) {
GeoPoint p = new GeoPoint((int) (addresses.get(0).getLatitude() * 1E6),
(int) (addresses.get(0).getLongitude() * 1E6));

locations.add(new OverlayItem(p ,"Kaufland", "Magic Kingdom"));

}
} catch (IOException e) {
e.printStackTrace();
}
populate();
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
super.draw(canvas, mapView, shadow);
boundCenterBottom(marker);
}
@Override
protected OverlayItem createItem(int i) {
return locations.get(i);
}
@Override
public int size() {
return locations.size();
}
}
}

这是 LogCat:

06-03 18:36:17.082: ERROR/AndroidRuntime(2296): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ShoppingList/com.ShoppingList.Shops.ShowMap}: java.lang.NullPointerException
06-03 18:36:17.082: ERROR/AndroidRuntime(2296): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
06-03 18:36:17.082: ERROR/AndroidRuntime(2296): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
06-03 18:36:17.082: ERROR/AndroidRuntime(2296): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
06-03 18:36:17.082: ERROR/AndroidRuntime(2296): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
06-03 18:36:17.082: ERROR/AndroidRuntime(2296): at android.os.Handler.dispatchMessage(Handler.java:99)
06-03 18:36:17.082: ERROR/AndroidRuntime(2296): at android.os.Looper.loop(Looper.java:123)
06-03 18:36:17.082: ERROR/AndroidRuntime(2296): at android.app.ActivityThread.main(ActivityThread.java:4363)
06-03 18:36:17.082: ERROR/AndroidRuntime(2296): at java.lang.reflect.Method.invokeNative(Native Method)
06-03 18:36:17.082: ERROR/AndroidRuntime(2296): at java.lang.reflect.Method.invoke(Method.java:521)
06-03 18:36:17.082: ERROR/AndroidRuntime(2296): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-03 18:36:17.082: ERROR/AndroidRuntime(2296): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-03 18:36:17.082: ERROR/AndroidRuntime(2296): at dalvik.system.NativeStart.main(Native Method)
06-03 18:36:17.082: ERROR/AndroidRuntime(2296): Caused by: java.lang.NullPointerException
06-03 18:36:17.082: ERROR/AndroidRuntime(2296): at com.google.android.maps.MapController.setCenter(MapController.java:345)
06-03 18:36:17.082: ERROR/AndroidRuntime(2296): at com.ShoppingList.Shops.ShowMap.onCreate(ShowMap.java:43)
06-03 18:36:17.082: ERROR/AndroidRuntime(2296): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-03 18:36:17.082: ERROR/AndroidRuntime(2296): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
06-03 18:36:18.881: INFO/Process(2296): Sending signal. PID: 2296 SIG: 9

最佳答案

您应该包括一个完整的日志跟踪,但 funPlaces.getCenter(); 有时不会返回有效点吗?

关于android - 强制关闭 mapController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6231196/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com