I have the following error in Java code and cause my application to crash. This error is due to the imageView
being null.
Error:Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setClipToOutline(boolean)' on a null object reference at ir.nasim_velayat.sorud.activity.Main2Activity.onCreate(Main2Activity.java:91)
And Java Codes:
Line 90 : imageView = (ImageView) findViewById(R.id.img_news_top);
Line 91 : imageView.setClipToOutline(true);
I anticipate that this error is due to the fact that I have not set the imageView
correctly, but I do not know how to set it correctly.
xml Code(ImageView):
<ImageView
android:id="@+id/img_news_top"
android:layout_width="280dp"
android:layout_height="150dp"
android:src="@drawable/bg_header"
android:background="@drawable/shape_radius"
android:scaleType="centerCrop"
android:layout_centerInParent="true"
/>