Android google maps v2 API 突然停止工作?

Android google maps v2 API suddenly stops working?

更新

我和同事N6试过了。有效。所以我买了一个新的开箱即用的 N6。我安装了 Play 服务。它失败了。

我整天都在做这个。它昨天一整天都运行良好。我只记得 gradle 让我交换网络(安全)来下载一些东西。大约一个小时后,我去建造.. nada。回到昨晚的检查,nada。它适用于我个人的 phone,但不适用于 nexus 6。哎呀,我什至将 #### phone 闪烁到 5.1 nexus 图像。纳达。清除了所有缓存的 gradle 文件,调整了最小 SDK 编号。没有什么。哦,还有 googled 几个小时。

我建,运行没问题。使用我的地图 CRASH 导航至 activity。虽然只在 nexus 上,但我的 note 4 没有崩溃。问题不是空指针,问题是

06-23 15:01:21.414  19516-19516/? W/ResourcesManager﹕ Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.
06-23 15:01:21.414  19516-19516/? W/ResourcesManager﹕ Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.

满满的

06-23 15:01:14.982  19516-19535/xxxx.xxxx.xxxx.mobility I/Adreno﹕ EGLInit: QTI Build: 01/29/15, 1bccc5d, I0ba6dce82d
06-23 15:01:14.990  19516-19535/xxxx.xxxx.xxxx.mobility I/OpenGLRenderer﹕ Initialized EGL, version 1.4
06-23 15:01:14.997  19516-19535/xxxx.xxxx.xxxx.mobility D/OpenGLRenderer﹕ Enabling debug mode 0
06-23 15:01:16.733  19516-19526/? I/art﹕ Ignoring second debugger -- accepting and dropping
06-23 15:01:21.407  19516-19516/? I/zzy﹕ Making Creator dynamically
06-23 15:01:21.414  19516-19516/? W/ResourcesManager﹕ Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.
06-23 15:01:21.414  19516-19516/? W/ResourcesManager﹕ Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.
06-23 15:01:21.443  19516-19516/? I/Google Maps Android API﹕ Google Play services client version: 7571000
06-23 15:01:21.452  19516-19516/? I/Google Maps Android API﹕ Google Play services package version: 7574430
06-23 15:01:21.845  19516-19516/? D/AndroidRuntime﹕ Shutting down VM
06-23 15:01:21.846  19516-19516/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: xxxx.xxxx.xxxx.mobility, PID: 19516
java.lang.NullPointerException: Attempt to invoke virtual method 'double android.location.Location.getLatitude()' on a null object reference
at xxxx.xxxx.xxxx.mobility.Map.MapPaneActivity.onMapReady(MapPaneActivity.java:109)
at com.google.android.gms.maps.MapFragment$zza.zza(Unknown Source)
at com.google.android.gms.maps.internal.zzm$zza.onTransact(Unknown Source)
at android.os.Binder.transact(Binder.java:380)
at com.google.android.gms.maps.internal.ba.a(SourceFile:82)
at com.google.maps.api.android.lib6.d.fz.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

去掉大部分包名。权限在最上面。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xcv.qwe.xxxxx.mobility"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="17"
    android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<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.WRITE_EXTERNAL_STORAGE"/>
<permission
    android:name="xcv.qwe.xxxxx.mobility.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />
<uses-permission android:name="xcv.qwe.xxxxx.mobility.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".StartSplashActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/title_activity_start_splash" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>


    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="xxxxx"
    <activity
        android:name=".StartSplashActivity"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:label="@string/title_activity_start_splash" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>


<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />

<meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />

<receiver
    android:name="xxxxx"
    android:enabled="true" >
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" >
        </action>
    </intent-filter>
</receiver>
<receiver
    android:name="xxxxxr"
    android:enabled="true" >
</receiver>
<receiver
    android:name="xxxxx"
    android:enabled="true" >
    <intent-filter>
        <action android:name="local.transition.initialize" />
        <action android:name="local.transition.exited_geofence" />
        <action android:name="local.transition.stopped_moving" />
        <action android:name="local.transition.stop_tracking" />
    </intent-filter>
</receiver>
<receiver android:name="xxxxx" >
    <intent-filter>
        <action android:name="android.intent.action.ACTION_BATTERY_LOW" />
        <action android:name="android.intent.action.ACTION_BATTERY_OKAY" />
    </intent-filter>
</receiver>

<service
    android:name="xxxxx"
    android:enabled="true" >
</service>
<service android:name="xxxxx" >
    <intent-filter>
        <action android:name="android.accounts.AccountAuthenticator" />
    </intent-filter>

    <meta-data
        android:name="android.accounts.AccountAuthenticator"
        android:resource="@xml/authenticator" />
</service>
<service
    android:name="xxxxx"
    android:enabled="true"
    android:exported="false" >
</service>
<service
    android:name="xxxxxe"
    android:enabled="true"
    android:exported="false" >
</service>
<service
    android:name="xxxxx"
    android:enabled="true"
    android:exported="false" >
</service>
<service
    android:name="xxxxx"
    android:exported="true"
    android:process=":sync" >
    <intent-filter>
        <action android:name="android.content.SyncAdapter" />
    </intent-filter>

    <meta-data
        android:name="android.content.SyncAdapter"
        android:resource="@xml/syncadapter" />
</service>

<provider
    android:name="xxxxx"
    android:authorities="xxxxx"
    android:exported="false"
    android:syncable="true" />

<activity
    android:name=".MainActivity"
    android:label="@string/app_name" >
</activity>
<activity
    android:name="xxxxx.MainActivity"
    android:label="@string/app_name" >
</activity>
<activity
    android:name=".InformedConsentActivity"
    android:label="@string/title_activity_informed_consent"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
</activity>
<activity
    android:name=".calendar.CalendarScrapeActivity"
    android:label="@string/title_activity_calendar_scrape"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
</activity>
<activity
    android:name=".calendar.CalendarViewerActivity"
    android:label="@string/title_activity_calendar_viewer"
    android:theme="@style/Theme.AppCompat.Light"
    >
</activity>

<activity
    android:name=".Map.MapPaneActivity"
    android:label="@string/title_activity_calendar_viewer"
    android:theme="@style/Theme.AppCompat.Light"
    >
</activity>
" />

    <receiver
        android:name="xxxxx"
        android:enabled="true" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" >
            </action>
        </intent-filter>
    </receiver>
    <receiver
        android:name="xxxxx"
        android:enabled="true" >
        <intent-filter>
            <action android:name="xxxxx" />
        </intent-filter>
    </receiver>
    <receiver
        android:name="xxxxx"
        android:enabled="true" >
        <intent-filter>
            <action android:name="local.transition.initialize" />
            <action android:name="local.transition.exited_geofence" />
            <action android:name="local.transition.stopped_moving" />
            <action android:name="local.transition.stop_tracking" />
        </intent-filter>
    </receiver>
    <receiver android:name="xxxxx" >
        <intent-filter>
            <action android:name="android.intent.action.ACTION_BATTERY_LOW" />
            <action android:name="android.intent.action.ACTION_BATTERY_OKAY" />
        </intent-filter>
    </receiver>

    <service
        android:name="xxxxx"
        android:enabled="true" >
    </service>
    <service android:name="xxxxx" >
        <intent-filter>
            <action android:name="android.accounts.AccountAuthenticator" />
        </intent-filter>

        <meta-data
            android:name="android.accounts.AccountAuthenticator"
            android:resource="@xml/authenticator" />
    </service>
    <service
        android:name="xxxxx"
        android:exported="true"
        android:process=":sync" >
        <intent-filter>
            <action android:name="android.content.SyncAdapter" />
        </intent-filter>

        <meta-data
            android:name="android.content.SyncAdapter"
            android:resource="@xml/syncadapter" />
    </service>

    <provider
        android:name="xxxxtracker.smap.StubContentProvider"
        android:authorities="xxxxtracker.provider"
        android:exported="false"
        android:syncable="true" />

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name="xxxxtracker.MainActivity"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".InformedConsentActivity"
        android:label="@string/title_activity_informed_consent"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
    </activity>
    <activity
        android:name=".calendar.CalendarScrapeActivity"
        android:label="@string/title_activity_calendar_scrape"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
    </activity>
    <activity
        android:name=".calendar.CalendarViewerActivity"
        android:label="@string/title_activity_calendar_viewer"
        android:theme="@style/Theme.AppCompat.Light"
        >
    </activity>

    <activity
        android:name=".Map.MapPaneActivity"
        android:label="@string/title_activity_calendar_viewer"
        android:theme="@style/Theme.AppCompat.Light"
        >
    </activity>
</application>

Executing tasks: [:mobility:assembleDebug]

Configuration on demand is an incubating feature.
:tracker:compileLint
:tracker:copyReleaseLint UP-TO-DATE
:tracker:preBuild UP-TO-DATE
:tracker:preReleaseBuild UP-TO-DATE
:tracker:checkReleaseManifest
:tracker:preDebugAndroidTestBuild UP-TO-DATE
:tracker:preDebugBuild UP-TO-DATE
:tracker:preDebugUnitTestBuild UP-TO-DATE
:tracker:preReleaseUnitTestBuild UP-TO-DATE
:tracker:prepareComAndroidSupportAppcompatV72200Library UP-TO-DATE
:tracker:prepareComAndroidSupportMediarouterV72200Library UP-TO-DATE
:tracker:prepareComAndroidSupportSupportV42200Library UP-TO-DATE
:tracker:prepareComGoogleAndroidGmsPlayServices750Library UP-TO-DATE
:tracker:prepareComGoogleAndroidGmsPlayServicesAds750Library UP-TO-DATE
:tracker:prepareComGoogleAndroidGmsPlayServicesAnalytics750Library UP-TO-DATE
:tracker:prepareComGoogleAndroidGmsPlayServicesAppindexing750Library UP-TO-DATE
:tracker:prepareComGoogleAndroidGmsPlayServicesAppinvite750Library UP-TO-DATE
:tracker:prepareComGoogleAndroidGmsPlayServicesAppstate750Library UP-TO-DATE
:tracker:prepareComGoogleAndroidGmsPlayServicesBase750Library UP-TO-DATE
:tracker:prepareComGoogleAndroidGmsPlayServicesCast750Library UP-TO-DATE
:tracker:prepareComGoogleAndroidGmsPlayServicesDrive750Library UP-TO-DATE
:tracker:prepareComGoogleAndroidGmsPlayServicesFitness750Library UP-TO-DATE
:tracker:prepareComGoogleAndroidGmsPlayServicesGames750Library UP-TO-DATE
:tracker:prepareComGoogleAndroidGmsPlayServicesGcm750Library UP-TO-DATE
:tracker:prepareComGoogleAndroidGmsPlayServicesIdentity750Library UP-TO-DATE
:tracker:prepareComGoogleAndroidGmsPlayServicesLocation750Library UP-TO-DATE
:tracker:prepareComGoogleAndroidGmsPlayServicesMaps750Library UP-TO-DATE
:tracker:prepareComGoogleAndroidGmsPlayServicesNearby750Library UP-TO-DATE
:tracker:prepareComGoogleAndroidGmsPlayServicesPanorama750Library UP-TO-DATE
:tracker:prepareComGoogleAndroidGmsPlayServicesPlus750Library UP-TO-DATE
:tracker:prepareComGoogleAndroidGmsPlayServicesSafetynet750Library UP-TO-DATE
:tracker:prepareComGoogleAndroidGmsPlayServicesWallet750Library UP-TO-DATE
:tracker:prepareComGoogleAndroidGmsPlayServicesWearable750Library UP-TO-DATE
:tracker:prepareReleaseDependencies
:tracker:compileReleaseAidl UP-TO-DATE
:tracker:compileReleaseRenderscript UP-TO-DATE
:tracker:generateReleaseBuildConfig UP-TO-DATE
:tracker:generateReleaseAssets UP-TO-DATE
:tracker:mergeReleaseAssets UP-TO-DATE
:tracker:generateReleaseResValues UP-TO-DATE
:tracker:generateReleaseResources UP-TO-DATE
:tracker:mergeReleaseResources UP-TO-DATE
:tracker:processReleaseManifest UP-TO-DATE
:tracker:processReleaseResources UP-TO-DATE
:tracker:generateReleaseSources UP-TO-DATE
:tracker:processReleaseJavaRes UP-TO-DATE
:tracker:compileReleaseJava UP-TO-DATE
:tracker:extractReleaseAnnotations UP-TO-DATE
:tracker:mergeReleaseProguardFiles UP-TO-DATE
:tracker:packageReleaseJar UP-TO-DATE
:tracker:compileReleaseNdk UP-TO-DATE
:tracker:packageReleaseJniLibs UP-TO-DATE
:tracker:packageReleaseLocalJar UP-TO-DATE
:tracker:packageReleaseRenderscript UP-TO-DATE
:tracker:packageReleaseResources UP-TO-DATE
:tracker:bundleRelease UP-TO-DATE
:mobility:preBuild UP-TO-DATE
:mobility:preDebugBuild UP-TO-DATE
:mobility:checkDebugManifest
:mobility:preReleaseBuild UP-TO-DATE
:mobility:prepareAndroidtrackerUnspecifiedLibrary UP-TO-DATE
:mobility:prepareComAndroidSupportAppcompatV72200Library UP-TO-DATE
:mobility:prepareComAndroidSupportMediarouterV72200Library UP-TO-DATE
:mobility:prepareComAndroidSupportSupportV42220Library UP-TO-DATE
:mobility:prepareComGithubAlamkanakAndroidWeekView123Library UP-TO-DATE
:mobility:prepareComGoogleAndroidGmsPlayServices750Library UP-TO-DATE
:mobility:prepareComGoogleAndroidGmsPlayServicesAds750Library UP-TO-DATE
:mobility:prepareComGoogleAndroidGmsPlayServicesAnalytics750Library UP-TO-DATE
:mobility:prepareComGoogleAndroidGmsPlayServicesAppindexing750Library UP-TO-DATE
:mobility:prepareComGoogleAndroidGmsPlayServicesAppinvite750Library UP-TO-DATE
:mobility:prepareComGoogleAndroidGmsPlayServicesAppstate750Library UP-TO-DATE
:mobility:prepareComGoogleAndroidGmsPlayServicesBase750Library UP-TO-DATE
:mobility:prepareComGoogleAndroidGmsPlayServicesCast750Library UP-TO-DATE
:mobility:prepareComGoogleAndroidGmsPlayServicesDrive750Library UP-TO-DATE
:mobility:prepareComGoogleAndroidGmsPlayServicesFitness750Library UP-TO-DATE
:mobility:prepareComGoogleAndroidGmsPlayServicesGames750Library UP-TO-DATE
:mobility:prepareComGoogleAndroidGmsPlayServicesGcm750Library UP-TO-DATE
:mobility:prepareComGoogleAndroidGmsPlayServicesIdentity750Library UP-TO-DATE
:mobility:prepareComGoogleAndroidGmsPlayServicesLocation750Library UP-TO-DATE
:mobility:prepareComGoogleAndroidGmsPlayServicesMaps750Library UP-TO-DATE
:mobility:prepareComGoogleAndroidGmsPlayServicesNearby750Library UP-TO-DATE
:mobility:prepareComGoogleAndroidGmsPlayServicesPanorama750Library UP-TO-DATE
:mobility:prepareComGoogleAndroidGmsPlayServicesPlus750Library UP-TO-DATE
:mobility:prepareComGoogleAndroidGmsPlayServicesSafetynet750Library UP-TO-DATE
:mobility:prepareComGoogleAndroidGmsPlayServicesWallet750Library UP-TO-DATE
:mobility:prepareComGoogleAndroidGmsPlayServicesWearable750Library UP-TO-DATE
:mobility:prepareComGoogleMapsAndroidAndroidMapsUtils034Library UP-TO-DATE
:mobility:prepareDebugDependencies
:mobility:compileDebugAidl UP-TO-DATE
:mobility:compileDebugRenderscript UP-TO-DATE
:mobility:generateDebugBuildConfig UP-TO-DATE
:mobility:generateDebugAssets UP-TO-DATE
:mobility:mergeDebugAssets UP-TO-DATE
:mobility:generateDebugResValues UP-TO-DATE
:mobility:generateDebugResources UP-TO-DATE
:mobility:mergeDebugResources UP-TO-DATE
:mobility:processDebugManifest UP-TO-DATE
:mobility:processDebugResources UP-TO-DATE
:mobility:generateDebugSources UP-TO-DATE
:mobility:processDebugJavaRes UP-TO-DATE
:mobility:compileDebugJava UP-TO-DATE
:mobility:compileDebugNdk UP-TO-DATE
:mobility:compileDebugSources UP-TO-DATE
:mobility:preDexDebug UP-TO-DATE
:mobility:dexDebug UP-TO-DATE
:mobility:validateMyConfigSigning
:mobility:packageDebug UP-TO-DATE
:mobility:zipalignDebug UP-TO-DATE
:mobility:assembleDebug UP-TO-DATE

BUILD SUCCESSFUL

Total time: 2.959 secs

Java代码。它主要是带有一些点击监听器的示例代码。我确实将地图更改为混合地图,从示例中...编辑我认为现在我看到了问题,这不是 google 示例。

        package xxx.xxx.xxx.mobility.Map;

    import android.app.Activity;
    import android.content.Intent;
    import android.location.Address;
    import android.location.Criteria;
    import android.location.Geocoder;
    import android.location.Location;
    import android.location.LocationManager;
    import android.os.Bundle;
    import android.text.TextUtils;
    import android.util.Log;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.Spinner;
    import android.widget.Toast;

    import com.google.android.gms.maps.CameraUpdateFactory;
    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.MapFragment;
    import com.google.android.gms.maps.OnMapReadyCallback;
    import com.google.android.gms.maps.model.LatLng;
    import com.google.android.gms.maps.model.MarkerOptions;

    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.List;

    import xxx.xxx.xxx.mobility.R;
    import xxx.xxx.xxx.mobility.calendar.CalendarConstants;


    public class MapPaneActivity extends Activity implements OnMapReadyCallback, GoogleMap.OnMapClickListener, GoogleMap.OnMapLongClickListener, Spinner.OnItemSelectedListener {

    final static int MAP_MAX_RESULTS = 10;
    final static String TAG = "MapPaneActivity";
    private Spinner map_selection_spinner;
    private ArrayAdapter<String>  mMapAddressAdapter;
    private LatLng mLatLng;
    private String mCurrentSelection = "";
    Button submit_map_button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map_pane);
        map_selection_spinner = (Spinner) findViewById(R.id.map_selection_spinner);
        submit_map_button = (Button) findViewById(R.id.submit_map_button);
        MapFragment mapFragment = (MapFragment) getFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
        map_selection_spinner.setOnItemSelectedListener(this);

        /*
         * The submit button will take the currently selected label from the spinner
          * and return to the calling activity.
         */

        submit_map_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle = new Bundle();
                bundle.putString(CalendarConstants.mapDataKey, mLatLng+CalendarConstants.divider+ mCurrentSelection);
                Intent intent = new Intent();
                intent.putExtras(bundle);
                setResult(RESULT_OK, intent);
                finish();
            }
        });

    }


    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) {
        if (mMapAddressAdapter != null) {
            submit_map_button.setEnabled(true);
            mCurrentSelection = mMapAddressAdapter.getItem(pos);
//            Toast.makeText(getApplicationContext(), mCurrentSelection, Toast.LENGTH_LONG).show();
        }
    }


    @Override
    public void onNothingSelected(AdapterView<?> adapterView) {

    }

    @Override
    public void onMapReady(GoogleMap map) {

        map.setMyLocationEnabled(true);
        map.setOnMapClickListener(this);
        map.setOnMapLongClickListener(this);

        /*
         * Set the map to our cuurent location
         */

        map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
        LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        Criteria criteria = new Criteria();
        String provider = locationManager.getBestProvider(criteria, true);
        Location myLocation = locationManager.getLastKnownLocation(provider);
        double latitude = myLocation.getLatitude();
        double longitude = myLocation.getLongitude();
        LatLng latLng = new LatLng(latitude, longitude);
        map.moveCamera(CameraUpdateFactory.newLatLng(latLng));

        // Zoom in the Google Map
        map.animateCamera(CameraUpdateFactory.zoomTo(17));
        map.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title(getResources().getString(R.string.your_local)));

    }


    /**
     * Handles the clicking of the map fragment.
     * This will mark a location and kick off populating the
     * spinner with addresses
     * @param latLng
     */
    @Override
    public void onMapClick(LatLng latLng) {
        mLatLng = latLng;
//        Toast.makeText(getApplicationContext(), "Clicked at.. " + mLatLng, Toast.LENGTH_LONG).show();
        List<Address> addressList;
        Geocoder geocoder = new Geocoder(getApplicationContext());
        double latitude  = mLatLng.latitude;
        double longitude = mLatLng.longitude;

        try {
            addressList = geocoder.getFromLocation(latitude, longitude, MAP_MAX_RESULTS);
            for(Address address : addressList){
                Log.d(TAG,address+" is at "+mLatLng);
            }
        }
        catch (IOException exception){
            Log.e(TAG, "Got an IO exeption!");

        }

    }

    @Override
    public void onMapLongClick(LatLng latLng) {
        onMapClick(latLng);
    }

}

您的问题在这里:

    Location myLocation = locationManager.getLastKnownLocation(provider);
    double latitude = myLocation.getLatitude();

根据您的堆栈跟踪,getLastKnownLocation() 正在返回 null。即 documented behavior. getLastKnownLocation() is only really good for optimistic checks on location, where if it does return null you either live without the location data or you use other methods to request location updates 并在该位置可用后使用该位置。