【问题标题】:Can't pass null for argument 'pathString' in child() how to resolve this error [closed]无法在 child() 中为参数“pathString”传递 null 如何解决此错误 [关闭]
【发布时间】:2021-04-15 05:55:24
【问题描述】:

如何解决此错误我正在尝试解决此错误但无法解决此错误我正在从适配器传递 ID 并想在付费活动中检索它请指导如何解决我是初学者请不要标记它重复

//Adapter
  Intent intent=new Intent(holder.itemView.getContext(),PayfeeActivity.class);
            intent.putExtra("id",id);
            holder.itemView.getContext().startActivity(intent);


//PayfeeActivity
 id=getIntent().getStringExtra("id");
  private void loadsdetail() {
    DatabaseReference ref= FirebaseDatabase.getInstance().getReference("Users");
    ref.child("Students").child(id).addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot ds) {
            //  for(DataSnapshot ds:snapshot.getChildren())
            // {
          //  String Nam=""+ds.child("name").getValue();
          //  String accounttype=""+ds.child("accounttype").getValue();
          //  String shopProfile=""+ds.child("sprofiles").getValue();
           // String Email=""+ds.child("email").getValue();
          //  String Shopaddress=""+ds.child("address").getValue();

            Sfphon=""+ds.child("fatherphon").getValue();

           // shopnametv.setText(Shopname);
            phon.setText(Sfphon);
          //  emailtv.setText(Email);
          ////  addresstv.setText(Shopaddress);

            try{

           //     Picasso.get().load(shopProfile).placeholder(R.drawable.ic_store_gray).into(sprofile);

            }catch (Exception e)
            {
              //  sprofile.setImageResource(R.drawable.ic_store_gray);
            }

            // }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError error) {

        }
    });
   }

【问题讨论】:

  • 当你运行这段代码时你得到了什么??
  • 不能在 child() 中为参数 'pathString' 传递 null
  • 你确定“id”不为空吗?
  • 最好将结构包含为 text,而不是链接和图像。这样,如果答案中需要它们,可以复制和粘贴它们。要获取您的 Firebase 结构,请使用 Firebase 控制台->导出 JSON,然后复制并粘贴您的结构的 sn-p。另外,请用您已完成的故障排除更新问题。您是否逐行浏览了代码,看看哪一行不起作用以及该行之前的变量是什么?

标签: java android database firebase firebase-authentication


【解决方案1】:

你需要像这样获得额外的意图

intent.getStringExtra("id")

之前

ref.child("Students").child(id).addListenerForSingleValueEvent(new ValueEventListener()

之后

ref.child("Students").child(intent.getStringExtra("id")).addListenerForSingleValueEvent(new ValueEventListener()

我希望这能奏效。

更多参考请查看https://stackoverflow.com/a/4233898/9502601

【讨论】:

  • 我已经拿到了身份证
  • id=getIntent().getStringExtra("id");
  • 你确定你设置的这个 id 是必需的而不是 null,因为它似乎是 null。
  • 我正在通过这个意图检查代码。getStringExtra("id") 应用程序停止崩溃,但没有数据显示
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多