実現したいこと
以下のurlのようにカルーセルを作成しようと考えていますが、エラーが出てきてしまい実行できません。layoutファイルでエラーが出てきてそうなエラー文です。
githubのurl
https://github.com/sayyam/carouselview
参考動画
https://www.youtube.com/watch?v=OxW78eOuvxE
発生している問題・エラーメッセージ
java.lang.RuntimeException: Unable to start activity ComponentInfo{local.hal.st42.android.carouselsample/local.hal.st42.android.carouselsample.MainActivity}: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class com.synnapps.carouselview.CarouselView Caused by: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class com.synnapps.carouselview.CarouselView Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class com.synnapps.carouselview.CarouselView Caused by: java.lang.reflect.InvocationTargetException Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/view/ViewPager$OnPageChangeListener; Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.view.ViewPager$OnPageChangeListener" on path: DexPathList[[zip file "/data/app/local.hal.st42.android.carouselsample-VV9TBEXEt4W0ehAMfiy1rA==/base.apk"],nativeLibraryDirectories=[/data/app/local.hal.st42.android.carouselsample-VV9TBEXEt4W0ehAMfiy1rA==/lib/arm64, /system/lib64, /system/vendor/lib64]] at local.hal.st42.android.carouselsample.MainActivity.onCreate(MainActivity.java:22) ↑ ここでエラーが出てきているっぽいです
該当のソースコード
MainActivity
1import androidx.appcompat.app.AppCompatActivity; 2 3import android.os.Bundle; 4import android.widget.ImageView; 5 6import com.synnapps.carouselview.CarouselView; 7import com.synnapps.carouselview.ImageListener; 8 9import java.util.ArrayList; 10import java.util.List; 11 12public class MainActivity extends AppCompatActivity { 13 14 List<Integer> images = new ArrayList<>(); 15 CarouselView carouselView; 16 17 @Override 18 protected void onCreate(Bundle savedInstanceState) { 19 super.onCreate(savedInstanceState); 20 setContentView(R.layout.activity_main); 21 22 carouselView = findViewById(R.id.carouselView); 23 images.add(R.drawable.sake); 24 images.add(R.drawable.store); 25 26 carouselView.setPageCount(images.size()); 27 carouselView.setImageListener(imageListener); 28 } 29 30 ImageListener imageListener = new ImageListener() { 31 @Override 32 public void setImageForPosition(int position, ImageView imageView) { 33 imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); 34 imageView.setImageResource(images.get(position)); 35 } 36 }; 37}
activity_main
1<?xml version="1.0" encoding="utf-8"?> 2<androidx.constraintlayout.widget.ConstraintLayout 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 xmlns:app="http://schemas.android.com/apk/res-auto" 5 xmlns:tools="http://schemas.android.com/tools" 6 android:layout_width="match_parent" 7 android:layout_height="match_parent" 8 tools:context=".MainActivity"> 9 10 <com.synnapps.carouselview.CarouselView 11 android:id="@+id/carouselView" 12 android:layout_width="match_parent" 13 android:layout_height="200dp" 14 app:fillColor="#FFFFFFFF" 15 app:pageColor="#00000000" 16 app:radius="6dp" 17 app:slideInterval="3000" 18 app:strokeColor="#FF777777" 19 app:strokeWidth="1dp" 20 tools:ignore="MissingConstraints"/> 21 22</androidx.constraintlayout.widget.ConstraintLayout>
回答1件
あなたの回答
tips
プレビュー