-1

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"
            />
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Reza
  • 47
  • 2
  • 12

2 Answers2

1

I think you have initialized wrong imageview.

Please check your R.id.img_news_top.
0

I understand the problem. I used objects of an irrelevant layer in main activity.

Reza
  • 47
  • 2
  • 12