我得到这个消息,当我点击购物车显示用户项目的详细信息,以检查出我不能解决这个问题,我尝试了任何方法,但我不明白
这是我的活动。当用户在主菜单中单击导航栏->购物车时,此活动将激活
public class Cartasli extends AppCompatActivity {
private RecyclerView recyclerView;
private RecyclerView.LayoutManager layoutManager;
private Button checkout;
private TextView totalHarga;
private ArrayList<Modelcartasli>modelcartasliArrayList;
private AdapterCartAsli adapterCartAsli;
private FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cartasli);
recyclerView = findViewById(R.id.cart_list);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
checkout = (Button) findViewById(R.id.btnchackout);
totalHarga = (TextView) findViewById(R.id.total_price);
firebaseAuth = FirebaseAuth.getInstance();
// showcartasli();
// loadcartdetail();
}
@Override
protected void onStart() {
super.onStart();
final DatabaseReference cartListRef = FirebaseDatabase.getInstance().getReference().child("Cart");
FirebaseRecyclerOptions<Modelcartasli> option = new FirebaseRecyclerOptions.Builder<Modelcartasli>()
.setQuery(cartListRef.child("User View").child(firebaseAuth.getUid()).child("BUKU").child("BukuId"),Modelcartasli.class).build();
FirebaseRecyclerAdapter<Modelcartasli, CartViewHolder> adapter = new FirebaseRecyclerAdapter<Modelcartasli, CartViewHolder>(option) {
@Override
protected void onBindViewHolder(@NonNull CartViewHolder cartViewHolder, int i, @NonNull Modelcartasli modelcartasli) {
cartViewHolder.Judulbuku.setText(modelcartasli.getPname());
cartViewHolder.hargabuku.setText(modelcartasli.getPharga());
cartViewHolder.Lamasewa.setText(modelcartasli.getPlamasewa());
}
@NonNull
@Override
public CartViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
{
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cart_item_layout,parent,false);
CartViewHolder holder = new CartViewHolder(view);
return holder;
}
};
recyclerView.setAdapter(adapter);
adapter.startListening();
}
这是我的支架。这是为了保存xml cartasliactivity,这是为了保存从数据库到活动的数据
public class CartViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener
{
public TextView Judulbuku,hargabuku,Lamasewa;
private ItemClickListner itemClickListner;
public CartViewHolder(@NonNull View itemView) {
super(itemView);
Judulbuku=itemView.findViewById(R.id.cart_buku_judul);
hargabuku=itemView.findViewById(R.id.cart_buku_harga);
Lamasewa=itemView.findViewById(R.id.cart_buku_lamasewa);
}
@Override
public void onClick(View view) {
itemClickListner.onClick(view,getAdapterPosition(),false);
}
public void setItemClickListner (ItemClickListner itemClickListner){
this.itemClickListner = itemClickListner;
}
我不知道怎么了,请帮帮我
此完整错误消息
e/androidruntime:致命异常:main
进程:com.example.sewabuku2,pid:21720
com.google.firebase.database.databaseexception:无法将java.lang.string类型的对象转换为com.example.sewabuku2.modelcartasli类型
还有这个模特卡塔斯利
private String pdate,pharga,pid,plamasewa,pname,ptime;
public Modelcartasli() {
}
public Modelcartasli(String pdate, String pharga, String pid, String plamasewa, String pname, String ptime) {
this.pdate = pdate;
this.pharga = pharga;
this.pid = pid;
this.plamasewa = plamasewa;
this.pname = pname;
this.ptime = ptime;
}
public String getPdate() {
return pdate;
}
public void setPdate(String pdate) {
this.pdate = pdate;
}
public String getPharga() {
return pharga;
}
public void setPharga(String pharga) {
this.pharga = pharga;
}
public String getPid() {
return pid;
}
public void setPid(String pid) {
this.pid = pid;
}
public String getPlamasewa() {
return plamasewa;
}
public void setPlamasewa(String plamasewa) {
this.plamasewa = plamasewa;
}
public String getPname() {
return pname;
}
public void setPname(String pname) {
this.pname = pname;
}
public String getPtime() {
return ptime;
}
public void setPtime(String ptime) {
this.ptime = ptime;
}
}
这个截图
在此处输入图像描述
这个json代码
"Cart" : {
"Admin View" : {
"qM6yj9Io86TSvUyL192EudNJJTy1" : {
"BUKU" : {
"BukuId" : {
"pdate" : "Dec 353, 2020",
"pharga" : "80000",
"pid" : "1608212863715",
"plamasewa" : "8 Minggu",
"pname" : "kevin1",
"ptime" : "20:57:31 PM"
}
}
},
"wxhr6zAm0kWajjRKO9S47fpeKHX2" : {
"BUKU" : {
"BukuId" : {
"pdate" : "Dec 353, 2020",
"pharga" : "10000",
"pid" : "1608059521100",
"plamasewa" : "1 Minggu",
"pname" : "cart",
"ptime" : "20:07:55 PM"
}
}
}
},
"User View" : {
"qM6yj9Io86TSvUyL192EudNJJTy1" : {
"BUKU" : {
"BukuId" : {
"pdate" : "Dec 353, 2020",
"pharga" : "80000",
"pid" : "1608212863715",
"plamasewa" : "8 Minggu",
"pname" : "kevin1",
"ptime" : "20:57:31 PM"
}
}
},
"wxhr6zAm0kWajjRKO9S47fpeKHX2" : {
"BUKU" : {
"BukuId" : {
"pdate" : "Dec 353, 2020",
"pharga" : "10000",
"pid" : "1608059521100",
"plamasewa" : "1 Minggu",
"pname" : "cart",
"ptime" : "20:07:55 PM"
}
}
}
}
},
暂无答案!
目前还没有任何答案,快来回答吧!