Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在云Firestore中发布身份证?_Java_Android_Firebase_Google Cloud Firestore - Fatal编程技术网

Java 如何在云Firestore中发布身份证?

Java 如何在云Firestore中发布身份证?,java,android,firebase,google-cloud-firestore,Java,Android,Firebase,Google Cloud Firestore,我想在我的帖子云Firestore中创建此结构: 我想在我的帖子云Firestore中创建此结构: Users | |-> UserId | |-> OneUserPosts | |->PostId | |-> PostContent

我想在我的帖子云Firestore中创建此结构: 我想在我的帖子云Firestore中创建此结构:

 Users
   |
   |-> UserId
           |
           |-> OneUserPosts
                   |
                   |->PostId
                         |
                         |-> PostContent
                             Comment 1
                             Comment 2
下面是我想创建帖子的活动: 我怎样才能把身份证交给我的岗位

  public class Add_Post extends AppCompatActivity {
         EditText posttext;
     FirebaseUser user;
 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add__post);
        user = FirebaseAuth.getInstance().getCurrentUser();
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        try {
            actionBar.setTitle("Write Your Post");

        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
        }catch (NullPointerException e){}
        posttext = findViewById(R.id.PostTextTextMultiLine);
  }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.addpostmenu, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {

        switch (item.getItemId()){
            case R.id.POST:

    savepost();

                break;
        }
        return super.onOptionsItemSelected(item);
    }

    private void savepost() {
        String Post = posttext.getText().toString();

        if (Post.length()<5){
            Toast.makeText(this, "Please enter at least 10 words ", Toast.LENGTH_SHORT).show();

        }
        else{
         try {

            CollectionReference postref = FirebaseFirestore.getInstance()
                    .collection("Users").document(user.getUid()).collection("OneUserPost");
            postref.add(new posttextlist(Post));
            Toast.makeText(this, "Successfully Posted", Toast.LENGTH_SHORT).show();
            finish();
            startActivity(new Intent(this,MainActivity.class));
}catch (NullPointerException e){}
        }


    }

}
public class Add\u Post扩展AppCompative活动{
编辑文本posttext;
FirebaseUser用户;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u add\u post);
user=FirebaseAuth.getInstance().getCurrentUser();
Toolbar Toolbar=findviewbyd(R.id.Toolbar);
设置支持操作栏(工具栏);
ActionBar ActionBar=getSupportActionBar();
getSupportActionBar().setDisplayShowHomeEnabled(true);
试一试{
setTitle(“写你的帖子”);
actionBar.setDisplayShowHomeEnabled(真);
actionBar.setDisplayHomeAsUpEnabled(true);
}捕获(NullPointerException e){}
posttext=findViewById(R.id.PostTextMultiline);
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
MenuInflater MenuInflater=getMenuInflater();
菜单充气器。充气(R.menu.addpostmenu,menu);
返回super.onCreateOptions菜单(菜单);
}
@凌驾
公共布尔值OnOptionItemSelected(@NonNull MenuItem item){
开关(item.getItemId()){
案例R.id.职位:
savepost();
打破
}
返回super.onOptionsItemSelected(项目);
}
私有void savepost(){
字符串Post=posttext.getText().toString();

如果(Post.length()使用以下代码行:

postref.add(new posttextlist(Post));
收藏参考:

使用指定的数据将新文档添加到此集合,并自动为其分配文档ID

如果不需要此行为,则应使用DocumentReference的:

覆盖此DocumentReference引用的文档

因此,您的代码应该如下所示:

CollectionReference postref = FirebaseFirestore.getInstance()
                .collection("Users").document(user.getUid())
                .collection("OneUserPost");
String id = postref.getId(); //Do what you need to do with this id
postref.document(id).set(new posttextlist(Post));

它没有在cloud firestore中存储数据。“它没有在cloud firestore中存储数据”没有足够的信息来查看错误。您是否有任何错误?您是否附加了侦听器以查看任务未成功时是否有错误?它没有显示任何错误。它显示toast。但未存储数据。com.google.firebase.firestore.FirebaseFirestoreException:PERMISSION\u DENIED:权限缺失或不足。在这种情况下在这种情况下,请设置安全规则以允许写入操作。