activity 跳转到mapactivity 报空指针异常 急~~~~~
从一个普通activity跳转到mapactivity时报错,以下是代码:
跳转代码:
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//showCityDialog();
Intent intent=new Intent();
intent.setClassName("com.kd", "com.kd.activitys.ShowMapActivity");
startActivity(intent);
}
mapactivity代码:
@Override
protected void onCreate(Bundle arg0) {
// TODO Auto-generated method stub
super.onCreate(arg0); 这里报错
mapView=new MapView(this, Utitls.getMapKey());
mapView.setSatellite(false);
mapView.setStreetView(false);
mapView.setClickable(true);
mapView.setBuiltInZoomControls(true);
mapCtrl=mapView.getController();
mapCtrl.setZoom(25);
lon=33.0000;
lat=33.0000;
GeoPoint centerP=new GeoPoint((int)(lat*1E6), (int)(lon*1E6));
mapCtrl.setCenter(centerP);
setContentView(mapView);
}
xml 文件:
</application>
<uses-library android:name="com.google.android.maps" />
</application>
这个也加上了
错误内容:
E/AndroidRuntime( 1753): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ufida.kdlife/com.kd.activitys.ShowMapActivity}: java.lang.NullPointerException
E/AndroidRuntime( 1753): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1752)
E/AndroidRuntime( 1753): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1768)
E/AndroidRuntime( 1753): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
E/AndroidRuntime( 1753): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:936)
E/AndroidRuntime( 1753): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 1753): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 1753): at android.app.ActivityThread.main(ActivityThread.java:3812)
E/AndroidRuntime( 1753): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1753): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 1753): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
E/AndroidRuntime( 1753): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
E/AndroidRuntime( 1753): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1753): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 1753): at android.app.ContextImpl.openFileOutput(ContextImpl.java:436)
E/AndroidRuntime( 1753): at android.content.ContextWrapper.openFileOutput(ContextWrapper.java:158)
E/AndroidRuntime( 1753): at com.google.common.io.android.AndroidPersistentStore.writeBlockX(Unknown Source)
E/AndroidRuntime( 1753): at com.google.common.io.android.AndroidPersistentStore.writeBlock(Unknown Source)
E/AndroidRuntime( 1753): at com.google.common.io.PreferenceStore.ensurePreferencesLoaded(Unknown Source)
E/AndroidRuntime( 1753): at com.google.common.io.PreferenceStore.readPreference(Unknown Source)
E/AndroidRuntime( 1753): at com.google.common.io.BasePersistentStore.readPreference(Unknown Source)
E/AndroidRuntime( 1753): at com.google.common.StaticUtil.readPreferenceAsDataInput(Unknown Source)
E/AndroidRuntime( 1753): at com.google.googlenav.datarequest.DataRequestDispatcher.loadOrRequestCookie(Unknown Source)
E/AndroidRuntime( 1753): at com.google.googlenav.datarequest.DataRequestDispatcher.<init>(Unknown Source)
E/AndroidRuntime( 1753): at com.google.googlenav.datarequest.DataRequestDispatcher.createInstance(Unknown Source)
E/AndroidRuntime( 1753): at com.google.android.maps.MapActivity.createMap(MapActivity.java:509)
E/AndroidRuntime( 1753): at com.google.android.maps.MapActivity.onCreate(MapActivity.java:409)
E/AndroidRuntime( 1753): at com.kd.activitys.ShowMapActivity.onCreate(ShowMapActivity.java:23)
E/AndroidRuntime( 1753): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 1753): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1706)
E/AndroidRuntime( 1753): ... 11 more
在mapactivity的super.onCreate(arg0);报错 头大了 谁来帮帮我。。。。。。。。。。。。。。
[解决办法]
新建项目用Google apis
[解决办法]
那是因为你的项目是引用google map,对于map他他有一个特定的项目。这个我的个人理解。