Android 开关语句调试

Android Switch Statement Debug

我的应用目前正在尝试连接用户和客户,在这里我正尝试通过 Firebase 和 GeoFire 来实现。但是由于某种原因,这个开关让我感到震惊

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.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)

当我 select 成为用户时,应用程序崩溃了,应用程序崩溃了。我已经查看过我是否在某处缺少 CustomerID 但看不到任何地方。突出的是 NullPointerException 错误。

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;
                }

我不确定我错过了什么,这真的很烦我,因为我认为它是正确的:(

在我看来,CustomerID 似乎是空的。在使用 switch 之前检查它。