【问题标题】:Geofire crashes when writing to Firebase写入 Firebase 时 Geofire 崩溃
【发布时间】:2018-12-08 21:06:02
【问题描述】:

我正在编写一个程序来将用户的 LatLng 数据上传到 Firebase。它通过单击按钮 btnAddPickUpLocation 来工作,然后上传到数据库。用户详细信息和 Uid 已在代码的其他部分启动,没有问题。

Lat Lng 目前是硬编码的,所以不是由于这个变量来源。

当我设置 Toast 以返回 Uid 时它会完美返回,而当我注释掉时它不会崩溃

mGeofire.setLocation(Uid, new GeoLocation(37.7853889, -122.4056973));

知道这句话有什么问题吗?

相关代码如下。

 RelativeLayout contentView = findViewById(R.id.contentView);
    btnAddPickUpLocation = contentView.findViewById(R.id.btnAddPickUpLocation);
    btnAddPickUpLocation.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //AddPickUpLocation(FirebaseAuth.getInstance().getCurrentUser().getUid());

            String Uid = FirebaseAuth.getInstance().getCurrentUser().getUid();

            Toast.makeText(getApplicationContext(), "hello " + Uid, Toast.LENGTH_LONG).show();
            //addPickUpLocation(FirebaseAuth.getInstance().getCurrentUser().getUid());

            dbAddPickUpLocation = FirebaseDatabase.getInstance().getReference("Favourites");

            mGeofire = new GeoFire(dbAddPickUpLocation);

            mGeofire.setLocation(Uid, new GeoLocation(37.7853889, -122.4056973));

        }

异常详情如下

06-29 16:31:55.992 24528-24528/com.abc.getataxi E/AndroidRuntime: 致命异常: main 进程:com.abc.getataxi,PID:24528 java.lang.NoSuchMethodError: 没有虚拟方法 setValue(Ljava/lang/Object;Ljava/lang/Object;)Lcom/google/firebase/tasks/Task;在 Lcom/google/firebase/database/DatabaseReference 类中;或其超类(“com.google.firebase.database.DatabaseReference”的声明出现在 /data/app/com.abc.getataxi-51bdN05Z7tlQu3bNLaX2nQ==/split_lib_dependencies_apk.apk 中) 在 com.firebase.geofire.GeoFire.setLocation(GeoFire.java:182) 在 com.firebase.geofire.GeoFire.setLocation(GeoFire.java:154) 在 com.abc.getataxi.UserMainPage$2.onClick(UserMainPage.java:299) 在 android.view.View.performClick(View.java:6294) 在 android.view.View$PerformClick.run(View.java:24770) 在 android.os.Handler.handleCallback(Handler.java:790) 在 android.os.Handler.dispatchMessage(Handler.java:99) 在 android.os.Looper.loop(Looper.java:164) 在 android.app.ActivityThread.main(ActivityThread.java:6494) 在 java.lang.reflect.Method.invoke(本机方法) 在 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

【问题讨论】:

    标签: android firebase firebase-realtime-database geofire


    【解决方案1】:

    设法通过变通解决它。对于任何寻找的人,添加一个完成侦听器参数,如下所示。

    mGeofire.setLocation(Uid, new GeoLocation(37.7853889, -122.4056973), new GeoFire.CompletionListener() {
                        @Override
                        public void onComplete(String key, DatabaseError error) {
                            Toast.makeText(getApplicationContext(), "Done ", Toast.LENGTH_LONG).show();
                        }
                    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-29
      • 2018-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多