发在问问没人理,转到这里请教:使用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个回答

这句有需要?





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

use-permission ... ACCESS_FINE_LOCATION 你没有权限,要添加的,



这三个似乎应该在Application外面,不是里面.
访问网络的话要加Internet 权限.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问