0

我正在尝试加载地图。请参阅下面的代码

@Override
    public void onStart() {
        super.onStart();
        setUpMapIfNeeded();
    }

    private void setUpMapIfNeeded() {
        // Do a null check to confirm that we have not already instantiated the
        // map.
        if (mMap == null) {
            // Try to obtain the map from the SupportMapFragment.
            mMap = ((SupportMapFragment) getChildFragmentManager()
                    .findFragmentById(R.id.map_frag)).getMap();
            // Check if we were successful in obtaining the map.
            if (mMap != null) {
                setUpMap();
            }
        }
    }

    private void setUpMap() {
        mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title(
                "Marker"));
    }

日志错误

09-27 15:42:23.039: E/AndroidRuntime(15965): FATAL EXCEPTION: main
09-27 15:42:23.039: E/AndroidRuntime(15965): java.lang.NullPointerException
09-27 15:42:23.039: E/AndroidRuntime(15965): at com.chupamobile.android.nightclub.ContactUsFragment.setUpMapIfNeeded(ContactUsFragment.java:68)
09-27 15:42:23.039: E/AndroidRuntime(15965): at com.chupamobile.android.nightclub.ContactUsFragment.onStart(ContactUsFragment.java:59)
09-27 15:42:23.039: E/AndroidRuntime(15965): at android.support.v4.app.Fragment.performStart(Fragment.java:1502)
09-27 15:42:23.039: E/AndroidRuntime(15965): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:957)
09-27 15:42:23.039: E/AndroidRuntime(15965): at android.support.v4.app.FragmentManagerImpl.performPendingDeferredStart(FragmentManager.java:823)
09-27 15:42:23.039: E/AndroidRuntime(15965): at android.support.v4.app.FragmentManagerImpl.startPendingDeferredFragments(FragmentManager.java:1128)
09-27 15:42:23.039: E/AndroidRuntime(15965): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1477)
09-27 15:42:23.039: E/AndroidRuntime(15965): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
09-27 15:42:23.039: E/AndroidRuntime(15965): at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
09-27 15:42:23.039: E/AndroidRuntime(15965): at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
09-27 15:42:23.039: E/AndroidRuntime(15965): at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
09-27 15:42:23.039: E/AndroidRuntime(15965): at android.support.v4.view.ViewPager$3.run(ViewPager.java:244)
09-27 15:42:23.039: E/AndroidRuntime(15965): at android.os.Handler.handleCallback(Handler.java:605)
09-27 15:42:23.039: E/AndroidRuntime(15965): at android.os.Handler.dispatchMessage(Handler.java:92)
09-27 15:42:23.039: E/AndroidRuntime(15965): at android.os.Looper.loop(Looper.java:137)
09-27 15:42:23.039: E/AndroidRuntime(15965): at android.app.ActivityThread.main(ActivityThread.java:4517)
09-27 15:42:23.039: E/AndroidRuntime(15965): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 15:42:23.039: E/AndroidRuntime(15965): at java.lang.reflect.Method.invoke(Method.java:511)
09-27 15:42:23.039: E/AndroidRuntime(15965): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:985)
09-27 15:42:23.039: E/AndroidRuntime(15965): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:752)
09-27 15:42:23.039: E/AndroidRuntime(15965): at dalvik.system.NativeStart.main(Native Method)
09-27 15:42:25.299: E/Google Maps Android API(15965): Authorization failure.  Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
09-27 15:42:25.299: E/Google Maps Android API(15965): Ensure that the following correspond to what is in the API Console: Package Name: com.chupamobile.android.nightclub, API Key: AIzaSyCuRYM06KNkqt5rNp5XIc0a27Ns3lhsHjw, Certificate Fingerprint: 0B2737AF8A0C3550F32CCC21EA1A143210CE8770
4

2 回答 2

1

试试这个我的朋友,

  • 请尝试使用其他密钥。
  • 检查是否所有权限都已授予,例如:

    ACCESS_COARSE_LOCATION

    ACCESS_FINE_LOCATION

    互联网

  • 最后,只需检查 setUpMap() 方法。也许它会起作用

于 2013-09-27T09:57:38.547 回答
0

更新 SDK 和 Google Play 服务后,我遇到了完全相同的问题。这个答案为我解决了这个问题。

https://stackoverflow.com/a/15303445/1450564

于 2013-10-03T11:56:32.027 回答