2016-12-11 26 views
1

我有一個簡單的POJO類在這裏:不能寫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; 
    } 
} 

我想通過以下方法寫入火力地堡,並沒有什麼在火力地堡數據庫中所有發生的事情,所以它不是」寫作或認識參考。這可能與我的火力地堡/ 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); 
    } 
+0

未能設置值通常是由[安全規則]造成的(https://firebase.google.com/docs/database/security/快速開始)。將'CompletionListener'添加到'setValue()'。示例代碼如下:http://stackoverflow.com/a/38229289/4815718 –

+0

關於您對模擬器上運行的評論:模擬器鏡像通常滯後於新版本Firebase/Play服務的發佈。看到這個答案:http://stackoverflow.com/a/41104004/4815718 –

回答

3

首先檢查安全規則,你是否已經啓用與否書面許可...如果沒有能寫入權限...在下面的鏈接找到如何設置權限... https://firebase.google.com/docs/database/security/quickstart

+0

我注意到它發生在仿真器上,似乎沒有安裝最新的Google Play服務。它是來自官方Android虛擬設備的模擬器,所以我認爲它將完全有能力與Firebase集成 – tccpg288