androidandroid-photoview

ImageView cannot be cast to PhotoView


I am using the PhotoView library to display some images.

When I try to use PhotoView with Picasso, as shown in the sample I get ClassCastException on this line:

PhotoView photoView = (PhotoView) findViewById(R.id.imageViewTest);

This is what's shown in the stack trace:

Caused by: java.lang.ClassCastException: android.support.v7.widget.AppCompatImageView cannot be cast to uk.co.senab.photoview.PhotoView

Am I missing something?


Solution

  • You need to use the PhotoView in your XML too, not ImageView. Do something like following:

    <uk.co.senab.photoview.PhotoView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/imageViewTest"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>