Quickstart-android: i get error:Can't pass null for argument 'pathString' in child() once i signout

Created on 6 Apr 2017  路  2Comments  路  Source: firebase/quickstart-android

`public class Chats extends Fragment {
private RecyclerView rv;

private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private DatabaseReference mdatabasechat;
private String uid=null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.chat, container, false);
    mAuth=FirebaseAuth.getInstance();
    mAuthListener=new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            if (firebaseAuth.getCurrentUser()==null){

                Intent i = new Intent(getActivity(), Main2Activity.class);
                startActivity(i);
            }
            else
            {uid=mAuth.getCurrentUser().getUid();}
        }
    };
    mdatabasechat= FirebaseDatabase.getInstance().getReference().child("Chat").child(uid); //error in this line
    mdatabasechat.keepSynced(true);
    rv=(RecyclerView) rootView.findViewById(R.id.chat_list);
    onStart();
    rv.setLayoutManager(new LinearLayoutManager(getActivity()));
    return rootView;
}
public void onStart() {
    mAuth.addAuthStateListener(mAuthListener);
    super.onStart();

    FirebaseRecyclerAdapter<Blog,BlogViewHolder> firebaseRecyclerAdapter=new FirebaseRecyclerAdapter<Blog,BlogViewHolder>(
            Blog.class,
            R.layout.chat_row,
            BlogViewHolder.class,
            mdatabasechat
    ) {
        @Override
        protected void populateViewHolder(final BlogViewHolder viewHolder, final Blog model, int position) {

            final String uid=getRef(position).getKey();

            {
                viewHolder.setUsername(uid);
                viewHolder.setImage(getActivity().getApplicationContext(), uid);
                viewHolder.mView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getActivity(), SingleChatActivity.class);
                        intent.putExtra("uid", uid);
                        startActivity(intent);

                    }
                });}

        }
    };
    rv.setAdapter(firebaseRecyclerAdapter);
}
public static class BlogViewHolder extends RecyclerView.ViewHolder{
    View mView;
    FirebaseAuth mAuth;
    public DatabaseReference mdatabaseu;
    public BlogViewHolder(View ItemView)
    {
        super(ItemView);
        mView=ItemView;
        mAuth=FirebaseAuth.getInstance();
        mdatabaseu=FirebaseDatabase.getInstance().getReference().child("Users");
        mdatabaseu.keepSynced(true);
    }
    public void setUsername(final String uid)
    {
        final String[] username = {""};
        final TextView post_username=(TextView)mView.findViewById(R.id.uname);
        mdatabaseu.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                username[0] =dataSnapshot.child(uid).child("username").getValue().toString();
                post_username.setText(username[0]);

            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });


    }
    public void setImage(final Context ctx, final String uid) {
        final String[] image = {""};
        final ImageView post_image = (ImageView) mView.findViewById(R.id.uimg);

        mdatabaseu.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                image[0] = dataSnapshot.child(uid).child("image").getValue().toString();
                Picasso.with(ctx).load(image[0]).into(post_image);
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
    }
     /*Picasso.with(ctx).load(image).networkPolicy(NetworkPolicy.OFFLINE).into(post_image, new Callback() {
         @Override
         public void onSuccess() {
         }
         @Override
         public void onError() {
             Picasso.with(ctx).load(image).into(post_image);
         }
     });*/

}

}`

Most helpful comment

@Aki58 since you have not clearly explained what is going wrong (and what you'd like to happen) and this seems to be an issue in your code and note the quickstart code, please post this question on StackOverflow.

All 2 comments

@Aki58 since you have not clearly explained what is going wrong (and what you'd like to happen) and this seems to be an issue in your code and note the quickstart code, please post this question on StackOverflow.

hello I also got same issue

myRef_agent.child(uid).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// // This method is called once with the initial value and again whenever data at this location is updated.//
/* String agent_Name = (String) dataSnapshot.child("name").getValue();
String agent_email = (String) dataSnapshot.child("email").getValue();
String agent_address = (String) dataSnapshot.child("address").getValue();
String agent_city = (String) dataSnapshot.child("city").getValue();
String agent_phone = (String) dataSnapshot.child("phone").getValue();
name_Edittext.setText(agent_Name);
address_Edittext.setText(agent_address);
phone_Edittext.setText(agent_phone);
village_Edittext.setText(agent_city);
email_Edittext.setText(agent_email);/
/
if( dataSnapshot.child("uid").getValue();){

            }

*/

          if (dataSnapshot != null) {
                    name_Edittext.setText(dataSnapshot.child("name").getValue(String.class));
                    email_Edittext.setText(dataSnapshot.child("email").getValue(String.class));

                    // the same for the last name
                } else {
                    name_Edittext.setText("There is no matching data ");
                }
            Log.v("lisa", "number" + uid);

        }

        @Override
        public void onCancelled(DatabaseError error) {
            // Failed to read value
            Log.w(TAG, "Failed to read value.", error.toException());
        }
    });
}
Was this page helpful?
0 / 5 - 0 ratings