0

I'm trying to remove blue dot on my location and show customized image. People said it needs to change location button. And I found this answer. Google map for android my location custom button But it doesn't work for me. On a code, it looks good and no red-line. But when I initial it on my mobile and press the location button, it stopped.

Is there any body post up with full code? Every one recommend that answer, but I'm not sure which was wrong... I stick to this matter more than 3 days.... Please any body help me..

error on Android monitor

12-15 11:20:37.845 10853-10853/org.androidtown.realchangdeokgunge D/AndroidRuntime: Shutting down VM
12-15 11:20:37.855 10853-10853/org.androidtown.realchangdeokgunge W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x4166bd58)
12-15 11:20:37.855 10853-10853/org.androidtown.realchangdeokgunge E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                    Process: org.androidtown.realchangdeokgunge, PID: 10853
                                                                                    java.lang.NullPointerException
                                                                                        at org.androidtown.realchangdeokgunge.GPSActivity.getMyLocation(GPSActivity.java:118)
                                                                                        at org.androidtown.realchangdeokgunge.GPSActivity.access$000(GPSActivity.java:50)
                                                                                        at org.androidtown.realchangdeokgunge.GPSActivity$1.onClick(GPSActivity.java:135)
                                                                                        at android.view.View.performClick(View.java:4457)
                                                                                        at android.view.View$PerformClick.run(View.java:18501)
                                                                                        at android.os.Handler.handleCallback(Handler.java:733)
                                                                                        at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                        at android.os.Looper.loop(Looper.java:136)
                                                                                        at android.app.ActivityThread.main(ActivityThread.java:5068)
                                                                                        at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                        at java.lang.reflect.Method.invoke(Method.java:515)
                                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
                                                                                        at dalvik.system.NativeStart.main(Native Method)

error on Code

GPSActivity java:118
LatLng latLng = new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude());

*I use mLastLocation instead of "Double.parse...." in the above linked post. I don't know why but it shows error with red-line.

GPSActivity java:50

public class GPSActivity extends FragmentActivity implements OnMapReadyCallback,
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener,
        LocationListener,
        GoogleMap.OnInfoWindowClickListener{

GPSActivity java:135

getMyLocation();
Community
  • 1
  • 1
dalami0i
  • 25
  • 8

1 Answers1

0

mLastLocation is null. If you are getting it from getLastLocation(), if the device may return null instead of returning a valid location. You need to check to for it being null before trying to get at its members --

if(mLastLocation != null) {
    LatLng latLng = new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude());
    // .... whatever else you need to do
}
iagreen
  • 31,470
  • 8
  • 76
  • 90
  • Thank you for your answer! It was help a lot! I need to find out how to input data on mLastLocation.... I'm trying to "location" on getMylocation method. But when I put it on "location" value, I need to put it also in onClick method in setOnClickListener. The problem is that it doesn't works. A value in onClick method "location" made an error...... How could I put a value "location".....? – dalami0i Dec 15 '16 at 03:32