Can't pass null for argument 'pathString' in child()? This the error I'm getting when retrieving data from firebase

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-11 12:28:20

问题


I'm creating an app with firebase as a backend, First I got output but after few changes I did for intent then it shows like this, Can anyone help me to solve this error. I used if to check whether I'm getting data or not and It goes through that if condition still it shows null.

Activity 1:

   public class centerActivity extends AppCompatActivity {
        RecyclerView recyclerView;
        ArrayList<data> mArrayList;
        FrontlistAdapter mAdapter;
        FirebaseRecyclerOptions<data> options;
        FirebaseDatabase database = FirebaseDatabase.getInstance();
        DatabaseReference myRef = database.getReference().child("Data").child(" Center");
        ClickListner listener = ClickListner();
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_common_template);
    
        //     mArrayList = new ArrayList<>();
            TextView title = (TextView)findViewById(R.id.title);
            title.setText("Center");
    
            options = new FirebaseRecyclerOptions.Builder<data>()
                    .setQuery(myRef, data.class)
                   .build();
    
           recyclerView =(RecyclerView)findViewById(R.id.centerrecycler);
          recyclerView.setHasFixedSize(false);
           mAdapter = new FrontlistAdapter(options,centerActivity.this,listener);
            recyclerView.setLayoutManager(new LinearLayoutManager(this));
           recyclerView.setAdapter(mAdapter);
    
    
        }
    
    
        @Override
        protected void onStart() {
            super.onStart();
               mAdapter.startListening();
        }
    
        @Override
        protected void onStop() {
            super.onStop();
           mAdapter.stopListening();
        }
    
        private ClickListner ClickListner() {
            ClickListner listener = new ClickListner() {
                @Override
                public void onClick(View view, int position) {
    
    
                    int tag = (int) view.getTag();
    
                    if(tag == 0)
                    {
                        Intent intent = new Intent(centerActivity.this, Center_details.class);
                        intent.putExtra(Intent.EXTRA_TEXT,position);
                        startActivity(intent);
                    }
    
                }
            };
    
            return listener;
        }
    }

Activity 2:

  public class Center_details extends AppCompatActivity {
            private static final String TAG = "Center_Details";
         TextView Name, Address, Timing, About;
        String UsersId;
         @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_center_details);
           
                Name = (TextView) findViewById(R.id.name);
                Address = (TextView) findViewById(R.id.address);
                Timing = (TextView) findViewById(R.id.timing);
                About = (TextView) findViewById(R.id.About);
    ref = FirebaseDatabase.getInstance().getReference().child("Data").child(" Center");

        if (getIntent().hasExtra(Intent.EXTRA_TEXT)) {
            Log.i(TAG, "onCreate: Checking for input");
            UsersId  = getIntent().getStringExtra(Intent.EXTRA_TEXT);
            if ((!TextUtils.isEmpty(UsersId))){
            ref.child(UsersId).addValueEventListener(new ValueEventListener() {
                        @Override
                        public void onDataChange(@NonNull DataSnapshot snapshot) {
                            if (snapshot.hasChildren()) {
                                String name = snapshot.child("Name").getValue().toString();
                                String address = snapshot.child("Address").getValue().toString();
                                String timing = snapshot.child("Timing").getValue().toString();
                                String about = snapshot.child("About").getValue().toString();
          Name.setText(name);
                                Address.setText(address);
                                Timing.setText(timing);
                                About.setText(about);
        } }
              @Override
                        public void onCancelled(@NonNull DatabaseError error) {
                            Log.d(TAG, "onCancelled: DatabaseError Bossu");
                        }
                    });
                }
        
        
            }
        }

    Activity:
      Intent intent = new Intent(GamecenterActivity.this, Center_details.class);
                        intent.putExtra("User",position);
                        startActivity(intent);

Error:
Caused by: java.lang.NullPointerException: Can't pass null for argument 'pathString' in child()

Thank you!!.................


回答1:


you get null value through intent here is the issue

UsersId  = getIntent().getStringExtra("User");

if(!TextUtils.isEmpty(UsersId))

then call firebase



来源:https://stackoverflow.com/questions/66119047/cant-pass-null-for-argument-pathstring-in-child-this-the-error-im-getting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!