So , in my application , after registration it saves your personal info in firebase , with your UId (key value) , for example :
here, in this class i am trying to get there data here :
public class featured extends AppCompatActivity
{
FirebaseAuth auth;
DatabaseReference db;
String info = "";
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main_page);
auth = FirebaseAuth.getInstance();
Toolbar bar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(bar);
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialogInterface, int i)
{
switch(i)
{
case DialogInterface.BUTTON_NEGATIVE :
Toast.makeText(getApplicationContext(),"error",Toast.LENGTH_LONG).show();
finish();
break;
case DialogInterface.BUTTON_POSITIVE :
Toast.makeText(getApplicationContext(),"gratz",Toast.LENGTH_LONG).show();
break;
}
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("esaa tqveni infoi ? : "+info)
.setPositiveButton("ho ra",dialogClickListener)
.setNegativeButton("nw",dialogClickListener)
.show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.actions,menu);
return super.onCreateOptionsMenu(menu);
}
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.filter :
db = FirebaseDatabase.getInstance().getReference().child(auth.getCurrentUser().getUid());
db.addValueEventListener(new ValueEventListener()
{
public void onDataChange(DataSnapshot dataSnapshot)
{
for(DataSnapshot s : dataSnapshot.getChildren())
{
user usr = s.getValue(user.class);
Log.d("Value from : ",usr.getName());
}
}
public void onCancelled(DatabaseError databaseError)
{
Toast.makeText(getApplicationContext(), "yolo", Toast.LENGTH_LONG).show();
}
});
default:
return super.onOptionsItemSelected(item);
}
}
}
here is user model :
public class user
{
public String name;
public String lastname;
public String email;
public String piradi;
public user(String name,String lastname,String email,String piradi)
{
this.name = name;
this.lastname = lastname;
this.email = email;
this.piradi = piradi;
}
public String getPiradi()
{
return piradi;
}
public void setPiradi(String piradi)
{
this.piradi = piradi;
}
public String getEmail()
{
return email;
}
public void setEmail(String email)
{
this.email = email;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getLastname()
{
return lastname;
}
public void setLastname(String lastname)
{
this.lastname = lastname;
}
public Map<String,Object> toMap()
{
HashMap<String,Object> result = new HashMap<>();
result.put("name",name);
result.put("lastname",lastname);
result.put("email",email);
result.put("piradi",piradi);
return result;
}
}
So after I run a code it's giving me nothing , just nullpointerexception error. Please help me :)