qhutch / ElevationImageView

Imageview with elevation shadow
396 stars 46 forks source link

Crash on initialisation if ImageView doesn't have a drawable yet #7

Closed ValCanBuild closed 6 years ago

ValCanBuild commented 6 years ago

I want to use ElevationImageView for images I load from the network. The problem is that i get a crash in ElevationImageView.getBitmapFromDrawable if no drawable is currently on the ImageView. Logs:

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.drawable.Drawable.draw(android.graphics.Canvas)' on a null object reference
        at com.qhutch.elevationimageview.ElevationImageView.getBitmapFromDrawable(ElevationImageView.kt:167)
        at com.qhutch.elevationimageview.ElevationImageView.generateShadow(ElevationImageView.kt:143)
        at com.qhutch.elevationimageview.ElevationImageView.onDraw(ElevationImageView.kt:74)

Is there a way to have the shadow update/be creatd when setDrawable is called on the imageview?

qhutch commented 6 years ago

I'm sorry for that, this was a null check I didn't do, it should be fixed in v1.7