Search code examples
javaandroidandroid-imageviewandroid-support-libraryandroid-image

java.lang.NullPointerException warning after setting image resource


After defining a rescource for the my imageview, a warning is then returned. What can be done to get rid of this warning?

    imageView.setImage(ImageSource.resource(R.drawable.map));

Method invocation 'imageView.setImage(ImageSource.resource(R.drawable.map))' may produce 'jave.lang.NullPointerException'


Solution

  • It's just a warning, so you can ignore it if you have no reason to think that the variables are null, but you can just assert that the variable isn't null like so to get rid of it.

    assert imageView != null;
    imageView.setImage(ImageSource.resource(R.drawable.map));