1

I have a simple POJO class here:

@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;
     }
}

I am trying to write to Firebase via the following method and nothing is happening at all in the Firebase database, so it isn't writing or recognizing the reference. It may have to do with my Firebase/POJO mapping but I can't identify the cause:

    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);
   }
AL.
  • 36,815
  • 10
  • 142
  • 281
tccpg288
  • 3,242
  • 5
  • 35
  • 80
  • Failure to set a value is often caused by [security rules](https://firebase.google.com/docs/database/security/quickstart). Add a `CompletionListener` to `setValue()`. Example code here: http://stackoverflow.com/a/38229289/4815718 – Bob Snyder Dec 12 '16 at 01:45
  • Regarding your comment about running on an emulator: The emulator images often lag the release of the new versions of Firebase/Play Services. See this answer: http://stackoverflow.com/a/41104004/4815718 – Bob Snyder Dec 13 '16 at 01:03

1 Answers1

3

First check the security rules, whether you have enabled writing permission for it or not...If not enable writing permission...In the below link find how to set permissions...https://firebase.google.com/docs/database/security/quickstart

Jayamurugan
  • 542
  • 2
  • 10
  • I noticed it is happening on the emulator that does not appear to have the latest Google Play Services installed. It is an emulator from the official Android Virtual Device so I would presume it would be fully capable of integrating with Firebase – tccpg288 Dec 12 '16 at 20:51