weixin_42397995 2010-09-09 08:25
浏览 660
已采纳

发在问问没人理,转到这里请教:使用MapView异常:java.lang.SecurityException: Requires ACCESS_FINE_LOC

使用MapView异常:java.lang.SecurityException: Requires ACCESS_FINE_LOCATION or ACCESS
09-07 15:18:30.153: ERROR/AndroidRuntime(254): Uncaught handler: thread main exiting due to uncaught exception
09-07 15:18:30.208: ERROR/AndroidRuntime(254): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.joyband.demo/com.joyband.demo.AndroidDemo1}: java.lang.SecurityException: Requires ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permission
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2481)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2497)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1848)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.os.Handler.dispatchMessage(Handler.java:99)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.os.Looper.loop(Looper.java:123)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.app.ActivityThread.main(ActivityThread.java:4338)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at java.lang.reflect.Method.invokeNative(Native Method)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at java.lang.reflect.Method.invoke(Method.java:521)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at dalvik.system.NativeStart.main(Native Method)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): Caused by: java.lang.SecurityException: Requires ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permission
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.os.Parcel.readException(Parcel.java:1218)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.os.Parcel.readException(Parcel.java:1206)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.location.ILocationManager$Stub$Proxy.getLastKnownLocation(ILocationManager.java:778)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.location.LocationManager.getLastKnownLocation(LocationManager.java:944)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at com.joyband.demo.AndroidDemo1.getLocation(AndroidDemo1.java:41)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at com.joyband.demo.AndroidDemo1.onCreate(AndroidDemo1.java:29)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2444)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): ... 11 more

我的代码:
public class AndroidDemo1 extends MapActivity {
private MapView mapView;
private MapController mapController;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);//多点触摸
mapView.setSatellite(true);

mapController = mapView.getController();
mapController.setZoom(15);
mapController.animateTo(getLocation());

Log.i("AndroidDemo1", "MapView 启动");
}

@Override
public boolean isRouteDisplayed() {
return false;
}

private GeoPoint getLocation(){
LocationManager locationMgr = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = locationMgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

return new GeoPoint((int)(location.getLatitude()*1e6),(int)(location.getLongitude()*1e6));
}
}

我的AndroidManifest.xml文件配置:
<?xml version="1.0" encoding="utf-8"?>
package="com.joyband.demo"
android:versionCode="1"
android:versionName="1.0">

android:label="@string/app_name">













不知道什么原因,请哪位指点一下?

  • 写回答

2条回答 默认 最新

  • wshwrf 2010-09-12 09:39
    关注

    这句有需要?





    放外面就行了.把那句多的去了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问GPT语言模型怎么训练?
  • ¥15 已知平面坐标系(非直角坐标系)内三个点的坐标,反求两坐标轴的夹角
  • ¥15 webots有问题,无响应
  • ¥15 数据量少可以用MK趋势分析吗
  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证