Problem with java.lang.Float cannot be cast to java.lang.String

I have not tried that much as I am not too fluent in java

This is the error in the logcat

2019-05-05 22:48:22.632 536-536/com.example.seniorproject W/Bundle: Key getPairValue() expected String but value was a java.lang.Float. The default value was returned. 2019-05-05 22:48:22.633 536-536/com.example.seniorproject W/Bundle: Attempt to cast generated internal exception: java.lang.ClassCastException: java.lang.Float cannot be cast to java.lang.String at android.os.BaseBundle.getPairValue(BaseBundle.java:200) at java.lang.reflect.Method.invoke(Native Method) at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:[email protected]@16.1.0:645) at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:[email protected]@16.1.0:167) at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:[email protected]@16.1.0:47) at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:[email protected]@16.1.0:663) at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:[email protected]@16.1.0:167) at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToPlainJavaTypes(com.google.firebase:[email protected]@16.1.0:60) at com.google.firebase.database.DatabaseReference.setValueInternal(com.google.firebase:[email protected]@16.1.0:292) at com.google.firebase.database.DatabaseReference.setValue(com.google.firebase:[email protected]@16.1.0:166) at com.example.seniorproject.TrackerService$3.onLocationResult(TrackerService.java:114) at com.google.android.gms.internal.location.zzau.notifyListener(Unknown Source) at com.google.android.gms.common.api.internal.ListenerHolder.notifyListenerInternal(Unknown Source) at com.google.android.gms.common.api.internal.ListenerHolder$zaa.handleMessage(Unknown Source) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6688) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)

private void requestLocationUpdates() {
    LocationRequest request = new LocationRequest();
    request.setInterval(10000);
    request.setFastestInterval(5000);
    request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    //Fused location provider should update firebase when receiving an update
    FusedLocationProviderClient client = LocationServices.getFusedLocationProviderClient(this);
    final String path = getString(R.string.firebase_path) + "/" + getString(R.string.transport_id);
    int permission = ContextCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION);
    if (permission == PackageManager.PERMISSION_GRANTED) {
        // Request location updates and when update received store in firebase
        client.requestLocationUpdates(request, new LocationCallback() {
            @Override
            public void onLocationResult(LocationResult locationResult) {
                DatabaseReference ref = FirebaseDatabase.getInstance().getReference(path);
                Location location = locationResult.getLastLocation();
                if (location != null) {
                    Log.d(TAG, "location update " + location);
                    ref.setValue(location);
                }
            }
        }, null);
    }
}

0 Answers