0

I am currently using android studio 2.1 and android idk marshmallow 6.0. I have an app that displays a list view of memorable places. The first activity consists of an empty list view and a button. When a button is clicked, it shows the map activity on which a user can long press a location and click back on the action bar; the app would then get the address of the 1st line and save it to the previous activity, which is the list view. If this particular item were clicked again, the location on the map would be displayed with the marker

To differentiate between adding a place and viewing a places, I use the startActivityForResult and startActivity respectively. I am not sure if this is a right way of achieving this.

The issue I am facing is the data is null when passing it to the map activity when ever I try and view the place only. Adding a new places, passes data back and forth without any issues.

Any help is appreciated.

places.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //get the position of the object from the hashmap
            Coordinates coordinates = geoCoordinates.get(position);
            Intent viewPlace = new Intent(MainActivity.this, MapsActivity.class);
            viewPlace.putExtra("sentlatitude", coordinates.latitude);
            viewPlace.putExtra("sentlongitude", coordinates.longitude);
            Log.i("Map Info#############", "Clicked starting maps activity");
            MainActivity.this.startActivity(viewPlace);
        }

This is the stack trace

08-02 09:18:54.089 3559-3559/com.example.joel.memorableplaces E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.joel.memorableplaces, PID: 3559 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.joel.memorableplaces/com.example.joel.memorableplaces.MapsActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.trim()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2434) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494) at android.app.ActivityThread.access$900(ActivityThread.java:157) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5551) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.trim()' on a null object reference at java.lang.StringToReal.parseDouble(StringToReal.java:263) at java.lang.Double.parseDouble(Double.java:301) at java.lang.Double.valueOf(Double.java:338) at com.example.joel.memorableplaces.MapsActivity.onCreate(MapsActivity.java:55) at android.app.Activity.performCreate(Activity.java:6272) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494)  at android.app.ActivityThread.access$900(ActivityThread.java:157)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5551)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) 

Jamie Barker
  • 8,145
  • 3
  • 29
  • 64
Spindoctor
  • 434
  • 3
  • 17

0 Answers0