Прописал метод получения имени и фото.
Вот полное активити
public class HomeActivity extends AppCompatActivity {
private ImageView button_cart,image_but_saat;
private TextView textname_hame;
private DatabaseReference prodReference;
private RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
recyclerView=(RecyclerView) findViewById(R.id.recycle_product);
prodReference= FirebaseDatabase.getInstance().getReference().child("Products");
button_cart=(ImageView) findViewById(R.id.button_cart);
image_but_saat=(ImageView) findViewById(R.id.image_but_saat);
layoutManager=new LinearLayoutManager(this);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(layoutManager);
textname_hame=(TextView) findViewById(R.id.textname_hame);
textname_hame.setText(Prevalent.currentOnlineUser.getName());
Picasso.get().load(Prevalent.currentOnlineUser.getImage()).into(image_but_saat);
image_but_saat.setOnClickListener(new View.OnClickListener() {
Prevalent(где записан currentOnlineUser)
public class Prevalent {
public static Users currentOnlineUser;
public static final String UserPhoneKey="UserPhone";
public static final String UserPasswordKey="UserPassword";
}
User model где записаны стринги
public class Users {
private String name,phone,password,image;
public Users(){
}
public Users(String name, String phone, String password,String image) {
this.name = name;
this.phone = phone;
this.password = password;
this.image=image;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
Вот ошибка
Process: door.one.marketplace, PID: 13150
java.lang.RuntimeException: Unable to start activity ComponentInfo{door.one.marketplace/door.one.marketplace.Users.HomeActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String door.one.marketplace.Model.Users.getName()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3539)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3699)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2135)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:8056)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String door.one.marketplace.Model.Users.getName()' on a null object reference
at door.one.marketplace.Users.HomeActivity.onCreate(HomeActivity.java:51)
at android.app.Activity.performCreate(Activity.java:8159)
at android.app.Activity.performCreate(Activity.java:8131)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1310)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3512)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3699)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2135)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:8056)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
Проблемная строка
textname_hame.setText(Prevalent.currentOnlineUser.getName());