0

Ok so my problem is that I have included a layout in my fragment view using <include.../> tag but whenever I try to initialize it throws a null pointer exception error

<include layout="@layout/pro_ocr" />

I tried a couple of methods to findViewById() like:

v.findViewById(R.id.crossProOCR);
getActivity.findViewById(R.id.crossProOCR);

but it didnt work a solution would be great help now

piotrek1543
  • 19,130
  • 7
  • 81
  • 94

1 Answers1

0

I'm guessing you are finding the id of the parent layout inside pro_ocr, hence you are getting an NPE. An include is used like any other view inside your layout. You need to give the include tag an id:

 <include
 android:id="@+id/proOcr"
 layout="@layout/pro_ocr" />

Then you can use it as View in your Fragment. Getting the ids of the views inside the included layout is similar to any other view.

private static
  • 745
  • 8
  • 17