[英]No setter/field for cardimage found on class
我已經檢查了類似問題的所有答案,但沒有任何幫助。 請幫幫我。 這是一個電子商務 android 應用程序。 我正在使用 firebase 來獲取卡片中的數據。 我在 firebase 中添加了 3 個產品,它在應用程序中顯示 3 個空卡。
代碼genericproductmodel.java:
package com.beingdev.magicprint.models;
import java.io.Serializable;
public class GenericProductModel implements Serializable {
public int cardid;
public String cardname;
public String cardimage;
public String carddiscription;
public float cardprice;
public GenericProductModel() {
}
public GenericProductModel(String carddiscription, int cardid, String cardimage, String cardname, float cardprice) {
this.carddiscription = carddiscription;
this.cardid = cardid;
this.cardimage = cardimage;
this.cardname = cardname;
this.cardprice = cardprice;
}
public String getCarddiscription() {
return carddiscription;
}
public void setCarddiscription(String carddiscription) {
this.carddiscription = carddiscription;
}
public int getCardid() {
return cardid;
}
public void setCardid(int cardid) {
this.cardid = cardid;
}
public String getCardimage() {
return cardimage;
}
public void setCardimage(String cardimage) {
this.cardimage = cardimage;
}
public String getCardname() {
return cardname;
}
public void setCardname(String cardname) {
this.cardname = cardname;
}
public float getCardprice() {
return cardprice;
}
public void setCardprice(float cardprice) {
this.cardprice = cardprice;
}
}
卡片代碼。java
package com.beingdev.magicprint.prodcutscategory;
import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import androidx.appcompat.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.airbnb.lottie.LottieAnimationView;
import com.beingdev.magicprint.Cart;
import com.beingdev.magicprint.IndividualProduct;
import com.beingdev.magicprint.NotificationActivity;
import com.beingdev.magicprint.R;
import com.beingdev.magicprint.models.GenericProductModel;
import com.beingdev.magicprint.networksync.CheckInternetConnection;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.squareup.picasso.Picasso;
public class Cards extends AppCompatActivity {
//created for firebaseui android tutorial by Vamsi Tallapudi
private RecyclerView mRecyclerView;
private StaggeredGridLayoutManager mLayoutManager;
private LottieAnimationView tv_no_item;
//Getting reference to Firebase Database
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference mDatabaseReference = database.getReference();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cards);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
//check Internet Connection
new CheckInternetConnection(this).checkConnection();
//Initializing our Recyclerview
mRecyclerView = findViewById(R.id.my_recycler_view);
tv_no_item = findViewById(R.id.tv_no_cards);
if (mRecyclerView != null) {
//to enable optimization of recyclerview
mRecyclerView.setHasFixedSize(true);
}
//using staggered grid pattern in recyclerview
mLayoutManager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(mLayoutManager);
//Say Hello to our new FirebaseUI android Element, i.e., FirebaseRecyclerAdapter
final FirebaseRecyclerAdapter<GenericProductModel, MovieViewHolder> adapter = new FirebaseRecyclerAdapter<GenericProductModel, MovieViewHolder>(
GenericProductModel.class,
R.layout.cards_cardview_layout,
MovieViewHolder.class,
//referencing the node where we want the database to store the data from our Object
mDatabaseReference.child("Products").child("Cards").getRef()
) {
@Override
protected void populateViewHolder(final MovieViewHolder viewHolder, final GenericProductModel model, final int position) {
if (tv_no_item.getVisibility() == View.VISIBLE) {
tv_no_item.setVisibility(View.GONE);
}
viewHolder.cardname.setText(model.getCardname());
viewHolder.cardprice.setText("₹ " + Float.toString(model.getCardprice()));
Picasso.with(Cards.this).load(model.getCardimage()).into(viewHolder.cardimage);
viewHolder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Cards.this, IndividualProduct.class);
intent.putExtra("product", getItem(position));
startActivity(intent);
}
});
}
};
mRecyclerView.setAdapter(adapter);
}
public void viewCart(View view) {
startActivity(new Intent(Cards.this, Cart.class));
finish();
}
//viewHolder for our Firebase UI
public static class MovieViewHolder extends RecyclerView.ViewHolder {
TextView cardname;
ImageView cardimage;
TextView cardprice;
View mView;
public MovieViewHolder(View v) {
super(v);
mView = v;
cardname = v.findViewById(R.id.cardcategory);
cardimage = v.findViewById(R.id.cardimage);
cardprice = v.findViewById(R.id.cardprice);
}
}
public void Notifications(View view) {
startActivity(new Intent(Cards.this, NotificationActivity.class));
finish();
}
@Override
public boolean onSupportNavigateUp() {
onBackPressed();
return true;
}
@Override
protected void onResume() {
super.onResume();
//check Internet Connection
new CheckInternetConnection(this).checkConnection();
}
}
日志:
W/ClassMapper: No setter/field for carddiscription found on class
com.beingdev.magicprint.d.a
No setter/field for cardimage found on class
com.beingdev.magicprint.d.a
No setter/field for cardname found on class
com.beingdev.magicprint.d.a
No setter/field for cardid found on class com.beingdev.magicprint.d.a
No setter/field for cardprice found on class
com.beingdev.magicprint.d.a
Firebase 截圖:
似乎您正在混淆您的代碼,因此您models.GenericProductModel
變成了da
。
要解決此問題,您可以在 proguard 文件中添加一條規則,以在混淆后保留 class。
# To keep the specific class and all its properties and members.
-keep class com.beingdev.magicprint.models.GenericProductModel { *; }
# or to keep all classes under com.beingdev.magicprint
-keep class com.beingdev.magicprint.** { *; }
或者,根據 Firebase 的文檔,您可以使用PropertyName()注釋對 class 字段進行注釋,以便在序列化時重命名字段,例如:
public class GenericProductModel implements Serializable {
@PropertyName("cardid")
public int cardId;
//...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.