0

I am trying to use PhotoView library with Kotlin.

But when I try to get photoView as in exaple:

val photoView = mView.findViewById<PhotoView>(R.id.zoomImageView)

I got error "Type argument is not within its bounds. Expected: View! Found: PhotoView"

Dima
  • 1,189
  • 1
  • 8
  • 12
  • you don't need to use `findViewById` in kotlin. – Tony May 13 '19 at 14:09
  • 1
    @Tony it's not true. In majority of the cases, yes, you no needed. But sometimes you have to use it (e.g. in own views or fragments) – Boken May 13 '19 at 14:14

1 Answers1

3

In your case issue is with typecasting either remove the typecasting or do something like this:

There are two ways you can fix this:

1)val photoView= mView.findViewById(R.id.zoomImageView)

2)val photoView:PhotoView= mView.findViewById(R.id.zoomImageView) as PhotoView

Mr. Patel
  • 1,379
  • 8
  • 21
  • Indeed the IDE should show `photoView` as `View`. Cast it using `as PhotoView`. – shkschneider May 13 '19 at 14:50
  • Ok then the issue seems to be with type casting you should let kotlin automatically decide the type so now try implementing the first solution i gave without typecast it should solve it – Mr. Patel May 14 '19 at 16:42