gpt4 book ai didi

android - 无法将 POJO 写入 Firebase 数据库

转载 作者:行者123 更新时间:2023-11-29 17:08:51 26 4
gpt4 key购买 nike

我这里有一个简单的 POJO 类:

@IgnoreExtraProperties
public class Poll {

private String Question;
private String Image_URL;

public Poll() {
}

public Poll(String Question, String Image_URL){
this.Question = Question;
this.Image_URL = Image_URL;
}


public String getQuestion() {
return Question;
}

public void setQuestion(String question) {
Question = question;
}

public String getImage_URL() {
return Image_URL;
}

public void setImage_URL(String image_URL) {
Image_URL = image_URL;
}
}

我正在尝试通过以下方法写入 Firebase,但 Firebase 数据库中没有发生任何事情,因此它没有写入或识别引用。这可能与我的 Firebase/POJO 映射有关,但我无法确定原因:

    mSubmitPollCreation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

// //TODO: Need to determine if this is proper epoch - i.e. does it account for time zones
// Calendar c = Calendar.getInstance();
// final String epochTime = String.valueOf(c.getTimeInMillis());
// mEpochRef = mBaseRef.child("Poll").child(epochTime);

//TODO: Need to check if poll requirements are added, i.e. Question, Answer, ......
//check if image has been loaded first
if (resultImageURL != null){
Map<String, Object> imageURL = new HashMap<String, Object>();
imageURL.put("Image_URL", resultImageURL);
// mEpochRef.updateChildren(imageURL);
} else {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.no_image_selected),Toast.LENGTH_LONG).show();
return;
}

Poll poll = new Poll(mCreatePollQuestion.getText().toString(), resultImageURL);
mBaseRef = FirebaseDatabase.getInstance().getReference();

mBaseRef.child("Polls").push().setValue(poll);
}

最佳答案

首先查看安全规则,是否开启了写入权限...如果没有开启写入权限...在下面的链接中找到如何设置权限... https://firebase.google.com/docs/database/security/quickstart

关于android - 无法将 POJO 写入 Firebase 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41091904/

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