gpt4 book ai didi

java - com.google.firebase.database.DatabaseException : Can't convert object of type java. lang.String 键入 com.example.bottary.Movie

转载 作者:行者123 更新时间:2023-12-02 04:41:18 24 4
gpt4 key购买 nike

我尝试在 recyclerview 中显示图像和 TextView ,但找不到问题,我将照片和文本放在 firebase 中的“”中,有什么问题吗?

Java

    MoviesRv.setLayoutManager(new LinearLayoutManager(HomeActivity.this, LinearLayout.HORIZONTAL,false));
reference = FirebaseDatabase.getInstance().getReference("Data");
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
List<Movie> first_tMovie = new ArrayList<>();
for(DataSnapshot dataSnapshot1: dataSnapshot.getChildren())
{
Movie p = dataSnapshot1.getValue(Movie.class);
first_tMovie.add(p);
}
MovieAdapter movieAdapter = new MovieAdapter(HomeActivity.this,first_tMovie);
MoviesRv.setAdapter(movieAdapter)

有模型类

Java

public class Movie {
private String title;
private String description;
private int thumbnail;
private String studio;
private String Rating;
private String streaminglink;

public Movie(String title , int thumbnail) {
this.title = title;
this.thumbnail = thumbnail;

}

public Movie(String title, int thumbnail) {
this.title = title;
this.thumbnail = thumbnail;
}

public String getTitle() {
return title;
}



public int getThumbnail() {
return thumbnail;
}

最佳答案

这是因为你无法将 Movie.class 的参数传递到 value 参数中:

改为更改此:

  Movie p = dataSnapshot1.getValue(Movie.class);

对此:

Movie p = (Movie)dataSnapshot1.getValue();

或者正确传递参数,即

Movie p = new Movie(datasnapshot1.child("x").getValue(),datasnapshot1.child("thumbnail").getValue());

关于java - com.google.firebase.database.DatabaseException : Can't convert object of type java. lang.String 键入 com.example.bottary.Movie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56515775/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com