我正在尝试根据谷歌地图api v2和google地点制作一个应用程序,接着是一个教程,我的应用程序运行良好。现在我添加了一段代码,用于使用地方api和在日志猫中愚弄错误显示
02-19 22:18:24.023: E/AndroidRuntime(21871): FATAL EXCEPTION: main
02-19 22:18:24.023: E/AndroidRuntime(21871): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.abhishekbietcs.locomap/com.abhishekbietcs.locomap.Mapme}: java.lang.NullPointerException
02-19 22:18:24.023: E/AndroidRuntime(21871): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
02-19 22:18:24.023: E/AndroidRuntime(21871): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
02-19 22:18:24.023: E/AndroidRuntime(21871): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-19 22:18:24.023: E/AndroidRuntime(21871): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
02-19 22:18:24.023: E/AndroidRuntime(21871): at android.os.Handler.dispatchMessage(Handler.java:99)
02-19 22:18:24.023: E/AndroidRuntime(21871): at android.os.Looper.loop(Looper.java:130)
02-19 22:18:24.023: E/AndroidRuntime(21871): at android.app.ActivityThread.main(ActivityThread.java:3687)
02-19 22:18:24.023: E/AndroidRuntime(21871): at java.lang.reflect.Method.invokeNative(Native Method)
02-19 22:18:24.023: E/AndroidRuntime(21871): at java.lang.reflect.Method.invoke(Method.java:507)
02-19 22:18:24.023: E/AndroidRuntime(21871): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
02-19 22:18:24.023: E/AndroidRuntime(21871): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
02-19 22:18:24.023: E/AndroidRuntime(21871): at dalvik.system.NativeStart.main(Native Method)
02-19 22:18:24.023: E/AndroidRuntime(21871): Caused by: java.lang.NullPointerException
02-19 22:18:24.023: E/AndroidRuntime(21871): at com.abhishekbietcs.locomap.Mapme.<init>(Mapme.java:48)
02-19 22:18:24.023: E/AndroidRuntime(21871): at java.lang.Class.newInstanceImpl(Native Method)
02-19 22:18:24.023: E/AndroidRuntime(21871): at java.lang.Class.newInstance(Class.java:1409)
02-19 22:18:24.023: E/AndroidRuntime(21871): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
02-19 22:18:24.023: E/AndroidRuntime(21871): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
02-19 22:18:24.023: E/AndroidRuntime(21871): ... 11 more
meinfest是
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.abhishekbietcs.locomap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<permission
android:name="com.abhishekbietcs.locomap.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.abhishekbietcs.locomap.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.abhishekbietcs.locomap.Mapme"
android:label="@string/title_activity_mapme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.abhishekbietcs.locomap.Aboutus"
android:label="@string/title_activity_mapme"
android:theme="@android:style/Theme.Dialog" >
<intent-filter>
<action android:name="android.intent.action.ABOUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.abhishekbietcs.locomap.ViewPrefrence"
android:label="@string/title_activity_mapme" >
<intent-filter>
<action android:name="android.intent.action.VIEWPREFRENCE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my key" />
</application>
仪表板活动的xml是
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Mapme" >
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
这里是oncreate方法
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("create","0");
setContentView(R.layout.activity_mapme);
SupportMapFragment mapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
Log.d("create","1");
googleMap = mapFragment.getMap();
Log.d("create","2");
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
Log.d("create","3");
}
googlemap变量是针对整个活动定义的,我真的无法理解出了什么问题,看到这个活动现在正在运行它是强制关闭,拉我的头发请帮帮我。谢谢提前