NPE on SupportMapFragment



我成功地用android maps v2构建了一个地图片段,它在我的智能手机上运行良好。现在我插上我的平板电脑,当我尝试启动地图活动时,我得到了一个NPE。我现在完全一无所知;甚至不知道错误的来源。有人能帮忙吗?thx

OnCreate of map activity:

FragmentManager myFragmentManager = getSupportFragmentManager();
    SupportMapFragment mySupportMapFragment = (SupportMapFragment)myFragmentManager.findFragmentById(R.id.customer_map_fragment);
    mMap = mySupportMapFragment.getMap();
    mMap.setMyLocationEnabled(true);                 <-- line 103 with the NPE
    mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);

customer_map_activity.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="match_parent"
         android:layout_height="match_parent" >
<fragment
        android:id="@+id/customer_map_fragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment"/>
</FrameLayout>

Logcat:

08-12 11:08:27.449: E/AndroidRuntime(3562): FATAL EXCEPTION: main
08-12 11:08:27.449: E/AndroidRuntime(3562): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cocus.salesapp/com.cocus.salesapp.TestCustomerMapActivity}: java.lang.NullPointerException
08-12 11:08:27.449: E/AndroidRuntime(3562):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2185)
08-12 11:08:27.449: E/AndroidRuntime(3562):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
08-12 11:08:27.449: E/AndroidRuntime(3562):     at android.app.ActivityThread.access$600(ActivityThread.java:142)
08-12 11:08:27.449: E/AndroidRuntime(3562):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
08-12 11:08:27.449: E/AndroidRuntime(3562):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 11:08:27.449: E/AndroidRuntime(3562):     at  android.os.Looper.loop(Looper.java:137)
08-12 11:08:27.449: E/AndroidRuntime(3562):     at android.app.ActivityThread.main(ActivityThread.java:4931)
08-12 11:08:27.449: E/AndroidRuntime(3562):     at java.lang.reflect.Method.invokeNative(Native Method)
08-12 11:08:27.449: E/AndroidRuntime(3562):     at java.lang.reflect.Method.invoke(Method.java:511)
08-12 11:08:27.449: E/AndroidRuntime(3562):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
08-12 11:08:27.449: E/AndroidRuntime(3562):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
08-12 11:08:27.449: E/AndroidRuntime(3562):     at dalvik.system.NativeStart.main(Native Method)
08-12 11:08:27.449: E/AndroidRuntime(3562): Caused by: java.lang.NullPointerException
08-12 11:08:27.449: E/AndroidRuntime(3562):     at com.fghj.salesapp.TestCustomerMapActivity.onCreate(TestCustomerMapActivity.java:103)

编辑:在手机上,它只在人像上运行。在平板电脑上,它被迫使用风景。

您可以通过调用GooglePlayServicesUtil.isGooglePlayServicesAvailable了解原因。

它将返回一个int值,您可以将其与ConnectionResult常量进行比较。

相关内容

  • 没有找到相关文章

最新更新