我正在编写一个程序,将用户的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 / Android运行时:致命异常:主要 流程: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)
答案 0 :(得分: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();
}
});