Siamak SiaSoft Siamak SiaSoft - 5 months ago 25
Java Question

how to solve setOnCameraChangeListener Error method in google map

i'm implementing google maps in an android project . But as soon as i moved my project into another PC machine i'm facing app crashs and this error message in my logcat console :

FATAL EXCEPTION: main
Process: com.egsdigital.dolan, PID: 24887
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.egsdigital.dolan/com.egsdigital.dolan.Activities.MainPage_Pasenger}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.maps.GoogleMap.setOnCameraChangeListener(com.google.android.gms.maps.GoogleMap$OnCameraChangeListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.maps.GoogleMap.setOnCameraChangeListener(com.google.android.gms.maps.GoogleMap$OnCameraChangeListener)' on a null object reference
at com.egsdigital.dolan.Activities.MainPage_Pasenger.onCreate(MainPage_Pasenger.java:178)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method)


and here where the error points on:

map.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition position) {
LatLngBounds bounds = map.getProjection().getVisibleRegion().latLngBounds;
mAdapter.setBounds(bounds);
}
});


thanks so much.

Answer

you must add new SHA1 into google console.
See this link for fetch SHA1 from your OS : How to get the SHA1 fingerprint certificate in android studio for debug mode

After fetching your SHA1 code, insert into console.developers and running Application .

Hope help you