My app is currently trying to connect a user and customer and here I am trying to do this via Firebase and GeoFire. However for some reason this switch is throwing me
2020-03-20 01:13:13.614 14508-14508/swift.fix.application I/Choreographer: Skipped 62 frames! The application may be doing too much work on its main thread.
2020-03-20 01:13:13.907 14508-14508/swift.fix.application D/AndroidRuntime: Shutting down VM
2020-03-20 01:13:13.935 14508-14508/swift.fix.application E/AndroidRuntime: FATAL EXCEPTION: main
Process: swift.fix.application, PID: 14508
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference
at swift.fix.application.TradesmanMapActivity$4.onLocationResult(TradesmanMapActivity.java:180)
at com.google.android.gms.internal.location.zzau.notifyListener(Unknown Source:4)
at com.google.android.gms.common.api.internal.ListenerHolder.notifyListenerInternal(com.google.android.gms:play-services-base@@17.1.0:17)
at com.google.android.gms.common.api.internal.ListenerHolder$zaa.handleMessage(com.google.android.gms:play-services-base@@17.1.0:6)
at android.os.Handler.dispatchMessage(Handler.java:106)
at com.google.android.gms.internal.base.zar.dispatchMessage(com.google.android.gms:play-services-base@@17.1.0:8)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
The app crashes when I select to be a user, and crashes the app. I have looked through to see if I am missing a CustomerID somewhere but can't see anywhere. The stand out is the NullPointerException error.
switch (CustomerID){
case "":
geoFireWorking.removeLocation(UserID, new GeoFire.CompletionListener() {
@Override
public void onComplete(String key, DatabaseError error) {
}
});
geoFireAvailable.setLocation(UserID, new GeoLocation(location.getLatitude(), location.getLongitude()), new GeoFire.CompletionListener() {
@Override
public void onComplete(String key, DatabaseError error) {
}
});
break;
default:
geoFireAvailable.removeLocation(UserID, new GeoFire.CompletionListener() {
@Override
public void onComplete(String key, DatabaseError error) {
}
});
geoFireWorking.setLocation(UserID, new GeoLocation(location.getLatitude(), location.getLongitude()), new GeoFire.CompletionListener() {
@Override
public void onComplete(String key, DatabaseError error) {
}
});
break;
}
I am not sure what I am missing and it is really bugging me as I assumed it was correct :(
It sounds like, to me, that CustomerID
is null. Check it before using switch
on it.