获取Placename,从地方选择器转移并在地图中显示

时间:2015-07-12 10:00:04

标签: java android xml google-maps google-places-api

我正在尝试制作一个简单的程序.. 单击第一个按钮时。 placepicker已打开。 ..选择一个地方,再次打开mainactivity ..当点击第二个按钮时..我想传递地名,Lat和long传递给showInMaps活动..但是当这个活动被打开时..应用程序停止。请帮忙

MainActvity.java

package com.example.akshay.myapplication;


import android.content.Context;
import android.content.Intent;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;

import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.ui.PlacePicker;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.MarkerOptions;


public class MainActivity extends ActionBarActivity implements View.OnClickListener {

    Button chooseLoc , showInMap;
    PlacePicker.IntentBuilder intentBuilder;
    private static final int PLACE_PICKER_REQUEST = 1;
    public LatLng gotLatLng;
    String placeName;
    String plName;
   Double gotLat, gotLong;


static final String LOG_TAG = "MainActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        chooseLoc = (Button) findViewById((R.id.bOpenMap));
        showInMap = (Button) findViewById(R.id.bShowInMap);
        chooseLoc.setOnClickListener(this);
        showInMap.setOnClickListener(this);


    }


    @Override
    public void onClick(View v) {

        switch (v.getId())
        {
            case R.id.bOpenMap:
            chooseLoc();
                break;
            case R.id.bShowInMap:

                Intent in = new Intent(MainActivity.this , showInMaps.class);
                in.putExtra("pName", plName);
                gotLat= gotLatLng.latitude;
                gotLong = gotLatLng.longitude;
                in.putExtra("Lat", gotLat);
                in.putExtra("Log", gotLong);

                startActivity(in);
                break;

        }
    }

    public void chooseLoc()

    {
        try {
            intentBuilder =new PlacePicker.IntentBuilder();

            Intent intent = intentBuilder.build(MainActivity.this);


            startActivityForResult(intent, PLACE_PICKER_REQUEST);

        } catch (GooglePlayServicesRepairableException e) {
            e.printStackTrace();
            Log.d(LOG_TAG, "Error In Repairable");
        } catch (GooglePlayServicesNotAvailableException e) {
            Toast.makeText(MainActivity.this, "Google Play Services is not available.",
                    Toast.LENGTH_LONG)
                    .show();
            Log.d(LOG_TAG, "Error In NotAvail");
        }
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == PLACE_PICKER_REQUEST) {
            if (resultCode == RESULT_OK) {
                Place place = PlacePicker.getPlace(data, this);
                gotLatLng = place.getLatLng();
                plName = (String) place.getName();
                placeName = String.format("Place: %s", place.getName());
                Toast.makeText(this, placeName, Toast.LENGTH_LONG).show();
                Toast.makeText(this, plName, Toast.LENGTH_LONG).show();

            }
        }
    }



}

showInMaps.java

package com.example.akshay.myapplication;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

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

/**
 * Created by Akshay on 7/12/2015.
 */
public class showInMaps extends Activity {
    Double lat, longi;
    GoogleMap mMaps;
    String place;
    String latLong;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.showinmaps);

        GoogleMap mMaps = null;

        Intent gotIntent = new Intent();

        place = gotIntent.getStringExtra("plName");
        lat = gotIntent.getExtras().getDouble("Lat");
        longi = gotIntent.getExtras().getDouble("Log");





        if (mMaps == null) {
            LatLng mm = new LatLng(lat, longi);
            mMaps = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
            mMaps.addMarker(new MarkerOptions().position(mm).title("Hello"));

        }
    }
}

activitymain.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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Choose Place"
        android:id="@+id/bOpenMap"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Show In Map"
        android:id="@+id/bShowInMap"
        android:layout_below="@+id/bOpenMap"
        android:layout_alignParentStart="true"
        android:layout_marginTop="48dp" />

</RelativeLayout>

showinmaps.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</RelativeLayout>

的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.akshay.myapplication" >



    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <!-- Required to show current location -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />


    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
       >
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version"/>

        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="AIzaSyCuZFbNaf6RGqU0C4uDAbNJQgMTDlsKqqE"/>
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        </activity>
        <activity
            android:name=".showInMaps"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.example.akshay.myapplication.SHOWINMAPS" />

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

        </activity>

    </application>

</manifest>

logcat的:

07-12 15:28:43.016     955-1758/? E/PersonaManagerService﹕ inState():  stateMachine is null !!
07-12 15:28:43.026     955-1258/? E/ActivityManager﹕ checkUser: useridlist=null, currentuser=0
07-12 15:28:43.026     955-1258/? E/ActivityManager﹕ checkUser: useridlist=null, currentuser=0
07-12 15:28:43.026     955-1258/? E/ActivityManager﹕ checkUser: useridlist=null, currentuser=0
07-12 15:28:43.026     955-1258/? E/ActivityManager﹕ checkUser: useridlist=null, currentuser=0
07-12 15:28:43.036    2399-2399/com.example.akshay.myapplication E/Zygote﹕ MountEmulatedStorage()
07-12 15:28:43.036    2399-2399/com.example.akshay.myapplication E/Zygote﹕ v2
07-12 15:28:43.046    2399-2399/com.example.akshay.myapplication E/SELinux﹕ [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
07-12 15:28:45.706     955-1756/? E/PersonaManagerService﹕ inState():  stateMachine is null !!
07-12 15:28:46.016     955-1004/? E/LocSvc_utils_cfg﹕ W/loc_read_sec_gps_conf: no secgps conf file, using defaults
07-12 15:28:46.046     955-1004/? E/LocSvc_utils_cfg﹕ W/loc_read_sec_gps_conf: no secgps conf file, using defaults
07-12 15:28:46.076     955-1006/? E/Sensors﹕ Sensor : Meta event
07-12 15:28:46.096     955-1537/? E/LocSvc_ApiV02﹕ I/virtual loc_api_adapter_err LocApiV02::startFix(const LocPosMode&):434]: position_mode=0.
07-12 15:28:46.116     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalRespCb(locClientHandleType, uint32_t, locClientRespIndUnionType, void*) line 125 QMI_LOC_SET_OPERATION_MODE_REQ_V02
07-12 15:28:46.126     955-1537/? E/LocSvc_ApiV02﹕ I/virtual loc_api_adapter_err LocApiV02::startFix(const LocPosMode&):434]: position_mode=0.
07-12 15:28:46.156     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalRespCb(locClientHandleType, uint32_t, locClientRespIndUnionType, void*) line 125 QMI_LOC_SET_OPERATION_MODE_REQ_V02
07-12 15:28:46.176      955-955/? E/LocSvc_flp﹕ I/===> int flp_inject_location(FlpLocation*) line 222
07-12 15:28:46.186     955-1263/? E/WifiStateMachine﹕ WifiStateMachine CMD_START_SCAN source 10034 txSuccessRate=9.97 rxSuccessRate=8.87 targetRoamBSSID=90:f6:52:77:9b:f0 RSSI=-69
07-12 15:28:46.186     955-1263/? E/WifiStateMachine﹕ [1,436,695,126,196 ms] noteScanStartWorkSource{10034} uid 10034
07-12 15:28:46.206     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalEventCb(locClientHandleType, uint32_t, locClientEventIndUnionType, void*) line 99 QMI_LOC_EVENT_ENGINE_STATE_IND_V02
07-12 15:28:46.226     955-1006/? E/Sensors﹕ Sensor : Meta event
07-12 15:28:47.066     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalEventCb(locClientHandleType, uint32_t, locClientEventIndUnionType, void*) line 99 QMI_LOC_EVENT_POSITION_REPORT_IND_V02
07-12 15:28:47.726     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalEventCb(locClientHandleType, uint32_t, locClientEventIndUnionType, void*) line 99 QMI_LOC_EVENT_GNSS_SV_INFO_IND_V02
07-12 15:28:47.786     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalEventCb(locClientHandleType, uint32_t, locClientEventIndUnionType, void*) line 99 QMI_LOC_EVENT_POSITION_REPORT_IND_V02
07-12 15:28:48.366     955-1263/? E/WifiStateMachine﹕ [1,436,695,128,369 ms] noteScanEnd WorkSource{10034}
07-12 15:28:48.366     955-1263/? E/WifiStateMachine﹕ wifi setScanResults statecom.android.server.wifi.WifiStateMachine$ConnectedState@3f98adf2 sup_state=COMPLETED debouncing=false
07-12 15:28:48.406      955-955/? E/LocSvc_flp﹕ I/===> int flp_inject_location(FlpLocation*) line 222
07-12 15:28:48.716     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalEventCb(locClientHandleType, uint32_t, locClientEventIndUnionType, void*) line 99 QMI_LOC_EVENT_GNSS_SV_INFO_IND_V02
07-12 15:28:48.776     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalEventCb(locClientHandleType, uint32_t, locClientEventIndUnionType, void*) line 99 QMI_LOC_EVENT_POSITION_REPORT_IND_V02
07-12 15:28:48.956      337-853/? E/audio_hw_primary﹕ [MAXIM] setDSM_tx_Control()....dsm_enable : 0, dsm_opened : 1, adev->mode : 0
07-12 15:28:48.976      337-853/? E/AudioFlinger﹕ releaseWakeLock_l() AudioOut_4
07-12 15:28:49.726     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalEventCb(locClientHandleType, uint32_t, locClientEventIndUnionType, void*) line 99 QMI_LOC_EVENT_GNSS_SV_INFO_IND_V02
07-12 15:28:49.786     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalEventCb(locClientHandleType, uint32_t, locClientEventIndUnionType, void*) line 99 QMI_LOC_EVENT_POSITION_REPORT_IND_V02
07-12 15:28:50.726     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalEventCb(locClientHandleType, uint32_t, locClientEventIndUnionType, void*) line 99 QMI_LOC_EVENT_GNSS_SV_INFO_IND_V02
07-12 15:28:50.786     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalEventCb(locClientHandleType, uint32_t, locClientEventIndUnionType, void*) line 99 QMI_LOC_EVENT_POSITION_REPORT_IND_V02
07-12 15:28:51.226     955-1263/? E/WifiStateMachine﹕ WifiStateMachine CMD_START_SCAN source 10034 txSuccessRate=8.99 rxSuccessRate=2.22 targetRoamBSSID=90:f6:52:77:9b:f0 RSSI=-71
07-12 15:28:51.226     955-1263/? E/WifiStateMachine﹕ [1,436,695,131,232 ms] noteScanStartWorkSource{10034} uid 10034
07-12 15:28:51.236     955-1006/? E/Sensors﹕ Sensor : Meta event
07-12 15:28:51.726     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalEventCb(locClientHandleType, uint32_t, locClientEventIndUnionType, void*) line 99 QMI_LOC_EVENT_GNSS_SV_INFO_IND_V02
07-12 15:28:51.796     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalEventCb(locClientHandleType, uint32_t, locClientEventIndUnionType, void*) line 99 QMI_LOC_EVENT_POSITION_REPORT_IND_V02
07-12 15:28:52.706     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalEventCb(locClientHandleType, uint32_t, locClientEventIndUnionType, void*) line 99 QMI_LOC_EVENT_GNSS_SV_INFO_IND_V02
07-12 15:28:52.766     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalEventCb(locClientHandleType, uint32_t, locClientEventIndUnionType, void*) line 99 QMI_LOC_EVENT_POSITION_REPORT_IND_V02
07-12 15:28:53.406     955-1263/? E/WifiStateMachine﹕ [1,436,695,133,409 ms] noteScanEnd WorkSource{10034}
07-12 15:28:53.426     955-1263/? E/WifiStateMachine﹕ wifi setScanResults statecom.android.server.wifi.WifiStateMachine$ConnectedState@3f98adf2 sup_state=COMPLETED debouncing=false
07-12 15:28:53.536      955-955/? E/LocSvc_flp﹕ I/===> int flp_inject_location(FlpLocation*) line 222
07-12 15:28:53.716     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalEventCb(locClientHandleType, uint32_t, locClientEventIndUnionType, void*) line 99 QMI_LOC_EVENT_GNSS_SV_INFO_IND_V02
07-12 15:28:53.776     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalEventCb(locClientHandleType, uint32_t, locClientEventIndUnionType, void*) line 99 QMI_LOC_EVENT_POSITION_REPORT_IND_V02
07-12 15:28:53.936    1967-2265/? E/Places﹕ e.a:898: GLS returned HTTP response code 500
07-12 15:28:54.376    1967-2265/? E/Places﹕ e.a:898: GLS returned HTTP response code 500
07-12 15:28:54.726     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalEventCb(locClientHandleType, uint32_t, locClientEventIndUnionType, void*) line 99 QMI_LOC_EVENT_GNSS_SV_INFO_IND_V02
07-12 15:28:54.786     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalEventCb(locClientHandleType, uint32_t, locClientEventIndUnionType, void*) line 99 QMI_LOC_EVENT_POSITION_REPORT_IND_V02
07-12 15:28:55.726     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalEventCb(locClientHandleType, uint32_t, locClientEventIndUnionType, void*) line 99 QMI_LOC_EVENT_GNSS_SV_INFO_IND_V02
07-12 15:28:55.786     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalEventCb(locClientHandleType, uint32_t, locClientEventIndUnionType, void*) line 99 QMI_LOC_EVENT_POSITION_REPORT_IND_V02
07-12 15:28:55.806      337-853/? E/AudioFlinger﹕ AudioFlinger acquireWakeLock
07-12 15:28:55.816      337-853/? E/AudioFlinger﹕ acquireWakeLock_l() AudioOut_4 status 0
07-12 15:28:55.826      337-852/? E/msm8974_platform﹕ platform_send_audio_calibration: sending audio calibration for snd_device(2) acdb_id(15)
07-12 15:28:55.856      337-852/? E/audio_hw_primary﹕ [MAXIM] setDSM_tx_Control()....dsm_enable : 1, dsm_opened : 0, adev->snd_card : 0, device_id : 1, adev->mode : 0
07-12 15:28:55.946     955-1004/? E/LocSvc_utils_cfg﹕ W/loc_read_sec_gps_conf: no secgps conf file, using defaults
07-12 15:28:55.966     955-1537/? E/LocSvc_ApiV02﹕ I/virtual loc_api_adapter_err LocApiV02::startFix(const LocPosMode&):434]: position_mode=0.
07-12 15:28:55.996     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalRespCb(locClientHandleType, uint32_t, locClientRespIndUnionType, void*) line 125 QMI_LOC_SET_OPERATION_MODE_REQ_V02
07-12 15:28:56.236     955-1263/? E/WifiStateMachine﹕ WifiStateMachine CMD_START_SCAN source 10034 txSuccessRate=29.50 rxSuccessRate=22.11 targetRoamBSSID=90:f6:52:77:9b:f0 RSSI=-75
07-12 15:28:56.236     955-1263/? E/WifiStateMachine﹕ [1,436,695,136,247 ms] noteScanStartWorkSource{10034} uid 10034
07-12 15:28:56.256     955-1006/? E/Sensors﹕ Sensor : Meta event
07-12 15:28:56.346    1967-1978/? E/DataBuffer﹕ Internal data leak within a DataBuffer object detected!  Be sure to explicitly call release() on all DataBuffer extending objects when you are done with them. (s{status=Status{statusCode=SUCCESS, resolution=null}, attributions=null})
07-12 15:28:56.356    1967-1978/? E/DataBuffer﹕ Internal data leak within a DataBuffer object detected!  Be sure to explicitly call release() on all DataBuffer extending objects when you are done with them. (internal object: com.google.android.gms.common.data.DataHolder@342c61ce)
07-12 15:28:56.356    1967-1978/? E/DataBuffer﹕ Internal data leak within a DataBuffer object detected!  Be sure to explicitly call release() on all DataBuffer extending objects when you are done with them. (s{status=Status{statusCode=SUCCESS, resolution=null}, attributions=null})
07-12 15:28:56.366    1967-1978/? E/DataBuffer﹕ Internal data leak within a DataBuffer object detected!  Be sure to explicitly call release() on all DataBuffer extending objects when you are done with them. (internal object: com.google.android.gms.common.data.DataHolder@300698ef)
07-12 15:28:56.426     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalEventCb(locClientHandleType, uint32_t, locClientEventIndUnionType, void*) line 99 QMI_LOC_EVENT_POSITION_REPORT_IND_V02
07-12 15:28:56.436     955-1703/? E/LocSvc_ApiV02﹕ I/<--- void globalEventCb(locClientHandleType, uint32_t, locClientEventIndUnionType, void*) line 99 QMI_LOC_EVENT_ENGINE_STATE_IND_V02
07-12 15:28:57.806      955-970/? E/PersonaManagerService﹕ inState():  stateMachine is null !!
07-12 15:28:57.846    2399-2655/com.example.akshay.myapplication E/Resources﹕ RunTimeException
    android.content.res.Resources$NotFoundException: Resource ID #0x7f020278
            at android.content.res.Resources.getValue(Resources.java:2345)
            at android.content.res.Resources.startRC(Resources.java:1059)
            at android.app.ActivityThread$mRunnable.run(ActivityThread.java:2527)
            at java.lang.Thread.run(Thread.java:818)
07-12 15:28:58.206    2399-2399/com.example.akshay.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.akshay.myapplication, PID: 2399
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.akshay.myapplication/com.example.akshay.myapplication.showInMaps}: java.lang.NullPointerException: Attempt to invoke virtual method 'double android.os.Bundle.getDouble(java.lang.String)' on a null object reference
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2712)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2777)
            at android.app.ActivityThread.access$900(ActivityThread.java:179)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1462)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5972)
            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:1399)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'double android.os.Bundle.getDouble(java.lang.String)' on a null object reference
            at com.example.akshay.myapplication.showInMaps.onCreate(showInMaps.java:32)
            at android.app.Activity.performCreate(Activity.java:6289)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2777)
            at android.app.ActivityThread.access$900(ActivityThread.java:179)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1462)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5972)
            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:1399)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
07-12 15:28:58.396     955-1263/? E/WifiStateMachine﹕ [1,436,695,138,404 ms] noteScanEnd WorkSource{10034}
07-12 15:28:58.396     955-1263/? E/WifiStateMachine﹕ wifi setScanResults statecom.android.server.wifi.WifiStateMachine$ConnectedState@3f98adf2 sup_state=COMPLETED debouncing=false
07-12 15:28:58.416      955-955/? E/LocSvc_flp﹕ I/===> int flp_inject_location(FlpLocation*) line 222
07-12 15:28:58.526     955-2678/? E/android.os.Debug﹕ !@Dumpstate > sdumpstate -k -t -z -d -o /data/log/dumpstate_app_error
07-12 15:28:59.586    1967-2265/? E/Places﹕ e.a:898: GLS returned HTTP response code 500
07-12 15:29:01.016     955-1005/? E/ViewRootImpl﹕ sendUserActionEvent() mView == null
07-12 15:29:01.026     955-1296/? E/OpenGLRenderer﹕ SFEffectCache:clear(), mSize = 0
07-12 15:29:01.306     955-1006/? E/Sensors﹕ Sensor : Meta event
07-12 15:29:01.376    1967-2265/? E/Places﹕ e.a:898: GLS returned HTTP response code 500

1 个答案:

答案 0 :(得分:3)

在showInMaps活动的onCreate方法中,你不应该说

Intent gotIntent = new Intent();

你应该说

Intent gotIntent = getIntent();

getIntent()将获得启动此活动的Intent,这就是持有所有额外内容的意图。当你说新的Intent()时,根本就没有额外的东西,因此当你说

时会出现NullPointerException
lat = gotIntent.getExtras().getDouble("Lat");

参考Android documentation on getIntent()