错误原因是文档==22137== Invalid read of size 8
==22137== at 0x1090EA: Var::gradient(Var*) const (in /home/median/so/deriv)
==22137== by 0x109109: Var::gradient(Var*) const (in /home/median/so/deriv)
==22137== by 0x108E12: main (in /home/median/so/deriv)
==22137== Address 0x5b82cd0 is 0 bytes inside a block of size 32 free'd
==22137== at 0x4C3123B: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==22137== by 0x109FC1: __gnu_cxx::new_allocator<std::pair<double, Var const*> >::deallocate(std::pair<double, Var const*>*, unsigned long) (in /home/median/so/deriv)
==22137== by 0x109CDD: std::allocator_traits<std::allocator<std::pair<double, Var const*> > >::deallocate(std::allocator<std::pair<double, Var const*> >&, std::pair<double, Var const*>*, unsigned long) (in /home/median/so/deriv)
==22137== by 0x109963: std::_Vector_base<std::pair<double, Var const*>, std::allocator<std::pair<double, Var const*> > >::_M_deallocate(std::pair<double, Var const*>*, unsigned long) (in /home/median/so/deriv)
==22137== by 0x1097BC: std::_Vector_base<std::pair<double, Var const*>, std::allocator<std::pair<double, Var const*> > >::~_Vector_base() (in /home/median/so/deriv)
==22137== by 0x1095EA: std::vector<std::pair<double, Var const*>, std::allocator<std::pair<double, Var const*> > >::~vector() (in /home/median/so/deriv)
==22137== by 0x109161: Var::~Var() (in /home/median/so/deriv)
==22137== by 0x108D95: main (in /home/median/so/deriv)
==22137== Block was alloc'd at
==22137== at 0x4C3017F: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==22137== by 0x10A153: __gnu_cxx::new_allocator<std::pair<double, Var const*> >::allocate(unsigned long, void const*) (in /home/median/so/deriv)
==22137== by 0x10A060: std::allocator_traits<std::allocator<std::pair<double, Var const*> > >::allocate(std::allocator<std::pair<double, Var const*> >&, unsigned long) (in /home/median/so/deriv)
==22137== by 0x109F03: std::_Vector_base<std::pair<double, Var const*>, std::allocator<std::pair<double, Var const*> > >::_M_allocate(unsigned long) (in /home/median/so/deriv)
==22137== by 0x109A8D: void std::vector<std::pair<double, Var const*>, std::allocator<std::pair<double, Var const*> > >::_M_realloc_insert<std::pair<double, Var const*> >(__gnu_cxx::__normal_iterator<std::pair<double, Var const*>*, std::vector<std::pair<double, Var const*>, std::allocator<std::pair<double, Var const*> > > >, std::pair<double, Var const*>&&) (in /home/median/so/deriv)
==22137== by 0x1098CF: void std::vector<std::pair<double, Var const*>, std::allocator<std::pair<double, Var const*> > >::emplace_back<std::pair<double, Var const*> >(std::pair<double, Var const*>&&) (in /home/median/so/deriv)
==22137== by 0x10973F: std::vector<std::pair<double, Var const*>, std::allocator<std::pair<double, Var const*> > >::push_back(std::pair<double, Var const*>&&) (in /home/median/so/deriv)
==22137== by 0x109520: operator*(Var const&, Var const&) (in /home/median/so/deriv)
==22137== by 0x108D6F: main (in /home/median/so/deriv)
getGeoPoint("geopoint")
和
getLongitude()
。仅当拉取多个文档时才会发生错误。如果我将经度和纬度注释掉,则所有文档都可以完美地载入我的recylerview
getLatitude()
错误的空指针异常
db.collection(COLLECTION_TAG)
.whereEqualTo("active", true)
.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
ServiceName = document.getString("service_name");
gsReference = storage.getReferenceFromUrl("gs://service-elf.appspot.com/"+ServiceName+".jpg");
StreetAddress = document.getString("address");
Website = document.getString("website");
ContactNumber = document.getString("contact");
Longitude = document.getGeoPoint("geopoint").getLongitude();
Latitude = document.getGeoPoint("geopoint").getLatitude();
String shours = ""+document.get("service_hours");
shours = shours.substring(1,shours.length()-1);
String[] hours = shours.split(",");
Hours = hours[getDay()];
Log.d("MainAct", document.getId() + " => " + document.getData() + shours + url);
services.add(new cService(url,ServiceName,StreetAddress,Website,ContactNumber,-30.111,18.111,Hours)}
Log中文档中的数据
E/AndroidRuntime: FATAL EXCEPTION: main
Process: za.co.sedi.serviceapp, PID: 14753
java.lang.NullPointerException: Attempt to invoke virtual method 'double com.google.firebase.firestore.GeoPoint.getLongitude()' on a null object reference
at za.co.sedi.serviceapp.MainActivity$1.onComplete(MainActivity.java:112)
at com.google.android.gms.tasks.zzj.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
使用Firebase数据库云Firestore的数据结构
链接到数据结构https://drive.google.com/open?id=1wQjV96dd_LuPr1pfupuQrR7Mv5O2pnpR
cService类
2ig2nIDo5QPxS1AkFT8F => {address=21 some road , cape town, western cape, service_name=alpha,contact=098765432,area=Ottery,active=true,website=www.alpha.com,service_hours=[7:00am - 6:00pm, 7:00am - 6:00pm, 7:00am - >6:00pm, 7:00am - 6:00pm, 7:00am - 6:00pm, 10:00am - 4:00pm, 12:00pm - 3:00pm],geopoint=GeoPoint { latitude=18.501747, longitude=-34.013823 }}
答案 0 :(得分:0)
在与Firebase支持人员交谈后,我发现问题是由于Firestore数据库中的文档损坏(损坏的文档可以通过不按字母顺序排列的字段来识别)而发生的。
通过重新创建文档并通过将active设置为false来停用损坏的文档来解决该问题,当我使用
查询集合时,将其停止显示db.collection(COLLECTION_TAG).whereEqualTo("active", true).get()...