Home > Blockchain >  AM trying to pass data image Url, fileurl into my movie app in the Tablayout am getting some erroes
AM trying to pass data image Url, fileurl into my movie app in the Tablayout am getting some erroes

Time:07-27

AM trying to pass data image Url, fileurl into my movie app in the Tablayout am getting some erroes This is the Main MainActivity

public class MainActivity extends AppCompatActivity {

BannerMoviesPagerAdapter bannerMoviesPagerAdapter;
TableLayout tableLayout;
ViewPager bannerMoviesViewPager;
List<BannerMovies> bannerMoviesList;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

   bannerMoviesList = new ArrayList<>();

    bannerMoviesList.add(new BannerMovies ( id:1, movieName: "Sharkula", imageUrl:"https://img.yts.mx/assets/images/movies/sharkula_2022/medium-cover.jpg", fileUrl"https://youtu.be/6SOEYXZK6Q4"));
   bannerMoviesList.add(new BannerMovies ( id:1, movieName: "test", imageUrl:"https://img.yts.mx/assets/images/movies/looking_for_jackie_2009/medium-cover.jpg", fileUrl"https://www.youtube.com/watch?v=ByYWL1SEe-k"));
   bannerMoviesList.add(new BannerMovies ( id:1, movieName: "test", imageUrl:"https://sdmoviespoint.mba/wp-content/uploads/2022/07/Khuda-Haafiz-Chapter-II-Agni-Pariksha-2022-Full-Movie-Download-Free.jpg", fileUrl"https://www.youtube.com/watch?v=ByYWL1SEe-k"));



}

private void setBannerMoviesPagerAdapter(List<BannerMovies> bannerMoviesList){

    bannerMoviesViewPager = findViewById(R.id.banner_viewPager);
    bannerMoviesPagerAdapter = new  BannerMoviesPagerAdapter(this, bannerMoviesList);
    bannerMoviesViewPager.setAdapter(bannerMoviesPagerAdapter);

}

}

//BannerMoviesPageAdapter//

public class BannerMoviesPagerAdapter extends PagerAdapter {

Context context;
List<BannerMovies> bannerMoviesList;

public BannerMoviesPagerAdapter(Context context, List<BannerMovies> bannerMoviesList) {
    this.context = context;
    this.bannerMoviesList = bannerMoviesList;
}

@Override
public int getCount() {
    return bannerMoviesList.size();
}

@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
    return view == object;
}

@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
   container.removeView((View) object);
}

@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {

    View view = LayoutInflater.from(context).inflate(R.layout.banner_movie_layout, null);

    ImageView bannerImage = view.findViewById(R.id.banner_image);


    Glide.with(context).load(bannerMoviesList.get(position).getImageUrl()).into(bannerImage);
    container.addView(view);
    return view;




}

}

BannerMovies public class BannerMovies {

Integer id;
String movieName;
String imageUrl;
String fileUrl;

public BannerMovies(Integer id, String movieName, String imageUrl, String fileUrl) {
    this.id = id;
    this.movieName = movieName;
    this.imageUrl = imageUrl;
    this.fileUrl = fileUrl;
}

public Integer getId() {
    return id;
}

public void setId(Integer id) {
    this.id = id;
}

public String getMovieName() {
    return movieName;
}

public void setMovieName(String movieName) {
    this.movieName = movieName;
}

public String getImageUrl() {
    return imageUrl;
}

public void setImageUrl(String imageUrl) {
    this.imageUrl = imageUrl;
}

public String getFileUrl() {
    return fileUrl;
}

public void setFileUrl(String fileUrl) {
    this.fileUrl = fileUrl;
}

}

CodePudding user response:

The Java syntax you've written isn't valid, try this one:

bannerMoviesList = new ArrayList<>();

   bannerMoviesList.add(new BannerMovies (1, "Sharkula","https://img.yts.mx/assets/images/movies/sharkula_2022/medium-cover.jpg", fileUrl"https://youtu.be/6SOEYXZK6Q4"));
   bannerMoviesList.add(new BannerMovies ( 1, "test","https://img.yts.mx/assets/images/movies/looking_for_jackie_2009/medium-cover.jpg", fileUrl"https://www.youtube.com/watch?v=ByYWL1SEe-k"));
   bannerMoviesList.add(new BannerMovies (1, "test","https://sdmoviespoint.mba/wp-content/uploads/2022/07/Khuda-Haafiz-Chapter-II-Agni-Pariksha-2022-Full-Movie-Download-Free.jpg", fileUrl"https://www.youtube.com/watch?v=ByYWL1SEe-k"));

CodePudding user response:

Your object creating syntax for BannerMovies is not correct. You should remove the words like id:, movieName:, imageUrl:, fileUrl: Your onCreate should look something like this:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

   bannerMoviesList = new ArrayList<>();

   bannerMoviesList.add(new BannerMovies (1,"Sharkula", "https://img.yts.mx/assets/images/movies/sharkula_2022/medium-cover.jpg", "https://youtu.be/6SOEYXZK6Q4"));
   bannerMoviesList.add(new BannerMovies (1,"test", "https://img.yts.mx/assets/images/movies/looking_for_jackie_2009/medium-cover.jpg", "https://www.youtube.com/watch?v=ByYWL1SEe-k"));
   bannerMoviesList.add(new BannerMovies ( 1, "test", "https://sdmoviespoint.mba/wp-content/uploads/2022/07/Khuda-Haafiz-Chapter-II-Agni-Pariksha-2022-Full-Movie-Download-Free.jpg", "https://www.youtube.com/watch?v=ByYWL1SEe-k"));
}
  • Related