gpt4 book ai didi

java - 我在此代码中收到 can't pass null for argument 'pathString' in child() 错误

转载 作者:行者123 更新时间:2023-12-02 08:54:24 28 4
gpt4 key购买 nike

我最近将 firebase 数据库 Orders 更改为 Location,我知道我错过了那里或这里的某些内容,但我无法准确找到问题。谁能指出我在这里做错了什么?

这是错误

2020-03-07 13:26:52.952 32564-32571/? E/zygote: Failed sending reply to debugger: Broken pipe2020-03-07 13:26:54.048 32564-32620/com.example.policeemergencysystem E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da2020-03-07 13:26:54.048 32564-32620/com.example.policeemergencysystem E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da2020-03-07 13:27:09.533 32564-32564/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.policeemergencysystem, PID: 32564 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.policeemergencysystem/com.example.policeemergencysystem.AdminViewMapsActivity}: java.lang.NullPointerException: Can't pass null for argument 'pathString' in child() at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) Caused by: java.lang.NullPointerException: Can't pass null for argument 'pathString' in child() at com.google.firebase.database.DatabaseReference.child(com.google.firebase:firebase-database@@19.2.1:96) at com.example.policeemergencysystem.AdminViewMapsActivity.onCreate(AdminViewMapsActivity.java:38) at android.app.Activity.performCreate(Activity.java:6975) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)  at android.app.ActivityThread.-wrap11(Unknown Source:0)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)  at android.os.Handler.dispatchMessage(Handler.java:105)  at android.os.Looper.loop(Looper.java:164)  at android.app.ActivityThread.main(ActivityThread.java:6541)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

这是代码。

package com.example.policeemergencysystem;

import android.os.Bundle;

import androidx.fragment.app.FragmentActivity;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

public class AdminViewMapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;
DatabaseReference mMaps;
private String userID = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_view_maps);
userID = getIntent().getStringExtra("uid");


// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);

mMaps = FirebaseDatabase.getInstance().getReference().child("Location").child(userID);
}


@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

mMaps.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {

double latitude = dataSnapshot.child("latitude").getValue(Double.class);
double longitude = dataSnapshot.child("longitude").getValue(Double.class);
LatLng latLng = new LatLng(latitude, longitude);
mMap.addMarker(new MarkerOptions().position(latLng).title("Location"));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latLng)
.zoom(12).build();
//Zoom in and animate the camera.
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}

这就是我的 Firebase 数据库的样子 1st one

I change this table. (Orders to Location)

最佳答案

您的数据库显示没有 uid,而只有硬编码的管理员名称。

mMaps = FirebaseDatabase.getInstance().getReference().child("Location").child("admin");

使用上面的数据库引用。

关于java - 我在此代码中收到 can't pass null for argument 'pathString' in child() 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60575841/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com