В фрагменте есть RecyclerView, в который должны загружаться картинки. Оданко при тесте приложение вылетает при переходе на фрагмент с этим RecyclerView. Как это можно исправить? Вот структура данных в database
модель для RecyclerView
@IgnoreExtraProperties
public class GalleryGridObject {
String companyImage;
public GalleryGridObject () {
}
public GalleryGridObject(String companyImage) {
this.companyImage = companyImage;
}
public String getCompanyImage() {
return companyImage;
}
public void setGalleryImage(String galleryImage) {
this.companyImage = galleryImage;
}
код адаптера RecyclerView
public class TestAdapter extends RecyclerView.Adapter<TestAdapter.ViewHolder> {
private Context mContext;
private ArrayList<GalleryGridObject> galleryArrayList;
public TestAdapter(Context mContext, ArrayList<GalleryGridObject> galleryArrayList){
this.mContext=mContext;
this.galleryArrayList=galleryArrayList;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_coupons, parent, false);
return new ViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
//GalleryGridObject gallery = galleryArrayList.get(position);
//Glide.with(mContext).load(galleryArrayList.get(position).getCompanyImage()).into(holder.imageGallery);
Picasso.get().load(galleryArrayList.get(position).getCompanyImage()).into(holder.imageGallery);
}
@Override
public int getItemCount() {
if(galleryArrayList==null) return 0;
return galleryArrayList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public ImageView imageGallery;
public ViewHolder(View view) {
super(view);
imageGallery = itemView.findViewById(R.id.coupons_picture);
}
}
}
код фрагмента с RecyclerView
public class TestFragment extends Fragment {
private ArrayList<GalleryGridObject> galleryList = new ArrayList<>();
private TestAdapter mAdapter;
private RecyclerView recyclerView;
private DatabaseReference mDatabase;
public TestFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_coupons, container, false);
recyclerView = view.findViewById(R.id.my_recycler_view);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.hasFixedSize();
mAdapter = new TestAdapter(getContext(), galleryList);
recyclerView.setAdapter(mAdapter);
recyclerView.setLayoutManager(layoutManager);
//mDatabase = FirebaseDatabase.getInstance().getReference().child("Data");
FirebaseDatabase database = FirebaseDatabase.getInstance();
mDatabase = database.getReference("Data");
mDatabase.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
getAllTask(dataSnapshot);
}
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
getAllTask(dataSnapshot);
}
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Log.w(TAG, "Failed to read value.", databaseError.toException());
}
});
return view;
}
private void getAllTask(DataSnapshot dataSnapshot){
galleryList = new ArrayList<GalleryGridObject>();
//galleryList.clear();
for (DataSnapshot ds : dataSnapshot.getChildren()) {
GalleryGridObject image = ds.getValue(GalleryGridObject.class);
galleryList.add(image);
}
System.out.println(galleryList.size());
}
}
Logcat
com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.String to type com.example.asus.socialmap.GalleryGridObject
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(com.google.firebase:firebase-database@@16.0.5:423)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-database@@16.0.5:214)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToCustomClass(com.google.firebase:firebase-database@@16.0.5:79)
at com.google.firebase.database.DataSnapshot.getValue(com.google.firebase:firebase-database@@16.0.5:212)
at com.example.asus.socialmap.TestFragment$1.onChildAdded(TestFragment.java:65)
at com.google.firebase.database.core.ChildEventRegistration.fireEvent(com.google.firebase:firebase-database@@16.0.5:79)
at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database@@16.0.5:63)
at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database@@16.0.5:55)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6798)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Виртуальный выделенный сервер (VDS) становится отличным выбором
Всем приветНаписал мини проект в которой из url достаю json, превращаю в обьекты и заношу в бд
Изучаю Spring по туториалу и создал Maven проект и теперь в pomxml лектор написал: