我正在开发一个显示地图视图的应用程序,并覆盖我从互联网下载的图像。
应用程序等待用户按下按钮,然后将地图以用户当前位置为中心。
一切都在某一时刻工作正常。但是我认为当我将我的测试手机 (Galaxy SIII) 更新为 Jelly Bean 时,事情变得一团糟。
当我按下按钮获取当前 GPS 位置、使地图居中并覆盖图像时,应用程序崩溃。
以下是 LogCat 的输出。我不确定它是什么意思,所以如果你能帮助我理解它,我将非常感激!
摘自我认为是问题的代码:
按钮监听器:
mUpdateButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0)
{
// Start listening for location
myLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,myLocationListener);
// Get Lat and Long coordinates, and format them
MyLat = (int)(myLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER).getLatitude()*1000000);
MyLong = (int)(myLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER).getLongitude()*1000000);
// Save the Lat and Long into a GeoPoint
GeoPoint initGeoPoint = new GeoPoint(MyLat,MyLong);
// Center location on current pos
CenterLocatio(initGeoPoint, 10);
// Stop listening for location
myLocationManager.removeUpdates(myLocationListener);
}
});
中心位置功能:
private void CenterLocatio(GeoPoint centerGeoPoint, int zoomLevel)
{
myMapController.animateTo(centerGeoPoint);
myMapController.setZoom(zoomLevel);
myLongitude.setText("Longitude: "+
String.valueOf((float)centerGeoPoint.getLongitudeE6()/1000000)
);
myLatitude.setText("Latitude: "+
String.valueOf((float)centerGeoPoint.getLatitudeE6()/1000000)
);
// Get location of the storage location
File extStore = Environment.getExternalStorageDirectory();
String PATH = extStore + "/data/tntechpie/";
// Add new overlay to Map
List<Overlay> mapOverlays = myMapView.getOverlays();
// Set drawable to the downloaded image from the storage location
//Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
@SuppressWarnings("deprecation")
Drawable drawable = new BitmapDrawable(PATH + "testMap.gif");
myItemizedOverlay itemizedoverlay = new myItemizedOverlay(drawable, this);
OverlayItem overlayitem = new OverlayItem(centerGeoPoint, "", "");
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
};
LogCat 输出:
01-22 12:34:31.062: I/MapActivity(6919): Handling network change notification:CONNECTED
01-22 12:34:31.062: E/MapActivity(6919): Couldn't get connection factory client
01-22 12:34:33.465: D/AndroidRuntime(6919): Shutting down VM
01-22 12:34:33.465: W/dalvikvm(6919): threadid=1: thread exiting with uncaught exception (group=0x41f44438)
01-22 12:34:33.475: E/AndroidRuntime(6919): FATAL EXCEPTION: main
01-22 12:34:33.475: E/AndroidRuntime(6919): java.lang.NullPointerException
01-22 12:34:33.475: E/AndroidRuntime(6919): at com.androidlocation.MainActivity$1.onClick(MainActivity.java:120)
01-22 12:34:33.475: E/AndroidRuntime(6919): at android.view.View.performClick(View.java:4198)
01-22 12:34:33.475: E/AndroidRuntime(6919): at android.view.View$PerformClick.run(View.java:17158)
01-22 12:34:33.475: E/AndroidRuntime(6919): at android.os.Handler.handleCallback(Handler.java:615)
01-22 12:34:33.475: E/AndroidRuntime(6919): at android.os.Handler.dispatchMessage(Handler.java:92)
01-22 12:34:33.475: E/AndroidRuntime(6919): at android.os.Looper.loop(Looper.java:137)
01-22 12:34:33.475: E/AndroidRuntime(6919): at android.app.ActivityThread.main(ActivityThread.java:4918)
01-22 12:34:33.475: E/AndroidRuntime(6919): at java.lang.reflect.Method.invokeNative(Native Method)
01-22 12:34:33.475: E/AndroidRuntime(6919): at java.lang.reflect.Method.invoke(Method.java:511)
01-22 12:34:33.475: E/AndroidRuntime(6919): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
01-22 12:34:33.475: E/AndroidRuntime(6919): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
01-22 12:34:33.475: E/AndroidRuntime(6919): at dalvik.system.NativeStart.main(Native Method)
01-22 12:34:41.924: I/Process(6919): Sending signal. PID: 6919 SIG: 9