我正在开发一个Android应用程序,它集成了googleMap。在过去的几个月里,我一直使用min SDK 12开发,一切都很顺利。我设法完美地使用了地图。今天我试图将min SDK更改为8,(更多人使用它)。为此,我使用了SupportMapFragment,但应用程序崩溃并且似乎无法正常工作。
以下是我的代码。
LinearLayout
android:id="@+id/layout_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/MyAppColor"
android:orientation="vertical"
>
<fragment
android:id="@+id/map_list"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
>
</fragment>
</LinearLayout
my java file
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
my manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dev.apk.myikubinfo"
android:versionCode="104"
android:versionName="1.0.4" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<permission
android:name="com.dev.apk.myikubinfo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.dev.apk.myikubinfo.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/AppTheme" >
<activity
android:name="com.dev.apk.myikubinfo.DashBoard"
android:label="@string/title_activity_dash_board"
android:screenOrientation="portrait" >
<meta-data
android:name="android.app.default_searchable"
android:value=".SearchActivity" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.dev.apk.myikubinfo.ChildCategory"
android:label="@string/title_activity_child_category"
android:screenOrientation="portrait" >
<meta-data
android:name="android.app.default_searchable"
android:value=".SearchActivity" />
</activity>
<activity
android:name="com.dev.apk.myikubinfo.BussinessByCategory"
android:label="@string/title_activity_bussiness_by_category"
android:screenOrientation="portrait" >
<meta-data
android:name="android.app.default_searchable"
android:value=".SearchActivity" />
</activity>
<activity
android:name="com.dev.apk.myikubinfo.BussinessInfo"
android:label="@string/title_activity_bussiness_info"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.dev.apk.myikubinfo.FullScreenViewActivity"
android:label="@string/title_activity_full_screen_view"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.dev.apk.myikubinfo.SearchableActivity"
android:label="@string/title_activity_searchable"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
<activity
android:name="com.dev.apk.myikubinfo.SearchActivity"
android:label="@string/title_activity_search"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAi9nb7-zYWA51-cKoG4eveMQ7nVap2gOU" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.dev.apk.myikubinfo.MapViewActivity"
android:label="@string/title_activity_map_view"
android:uiOptions="splitActionBarWhenNarrow">
<meta-data android:name="android.support.UI_OPTIONS"
android:value="splitActionBarWhenNarrow" />
</activity>
</application>
</manifest>
这是我的logcat
02-25 17:41:34.242: E/AndroidRuntime(6598): FATAL EXCEPTION: main
02-25 17:41:34.242: E/AndroidRuntime(6598): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dev.apk.myikubinfo/com.dev.apk.myikubinfo.BussinessByCategory}: java.lang.NullPointerException
02-25 17:41:34.242: E/AndroidRuntime(6598): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2001)
02-25 17:41:34.242: E/AndroidRuntime(6598): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2028)
02-25 17:41:34.242: E/AndroidRuntime(6598): at android.app.ActivityThread.access$600(ActivityThread.java:127)
02-25 17:41:34.242: E/AndroidRuntime(6598): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1179)
02-25 17:41:34.242: E/AndroidRuntime(6598): at android.os.Handler.dispatchMessage(Handler.java:99)
02-25 17:41:34.242: E/AndroidRuntime(6598): at android.os.Looper.loop(Looper.java:137)
02-25 17:41:34.242: E/AndroidRuntime(6598): at android.app.ActivityThread.main(ActivityThread.java:4508)
02-25 17:41:34.242: E/AndroidRuntime(6598): at java.lang.reflect.Method.invokeNative(Native Method)
02-25 17:41:34.242: E/AndroidRuntime(6598): at java.lang.reflect.Method.invoke(Method.java:511)
02-25 17:41:34.242: E/AndroidRuntime(6598): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
02-25 17:41:34.242: E/AndroidRuntime(6598): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
02-25 17:41:34.242: E/AndroidRuntime(6598): at dalvik.system.NativeStart.main(Native Method)
02-25 17:41:34.242: E/AndroidRuntime(6598): Caused by: java.lang.NullPointerException
02-25 17:41:34.242: E/AndroidRuntime(6598): at com.dev.apk.myikubinfo.BussinessByCategory.initilizeMap(BussinessByCategory.java:459)
02-25 17:41:34.242: E/AndroidRuntime(6598): at com.dev.apk.myikubinfo.BussinessByCategory.setMapFeatures(BussinessByCategory.java:622)
02-25 17:41:34.242: E/AndroidRuntime(6598): at com.dev.apk.myikubinfo.BussinessByCategory.onCreate(BussinessByCategory.java:276)
02-25 17:41:34.242: E/AndroidRuntime(6598): at android.app.Activity.performCreate(Activity.java:4479)
02-25 17:41:34.242: E/AndroidRuntime(6598): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
02-25 17:41:34.242: E/AndroidRuntime(6598): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1965)
02-25 17:41:34.242: E/AndroidRuntime(6598): ... 11 more
答案 0 :(得分:0)
您在清单文件中缺少元数据标记:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />