findViewById returns null for me in the ImageView widget. There is no error in logcat and nothing is displayed, which indicates what is happening. Correspondence of identifier and other images is correctly configured. Java and xml are linked by a class tag in xml pointing to a class defined in java, which is a descendant of RelativeLayout.
I tried changing the name R.id.more_icon1 and it did not work. Tried to clean and it didn't work. Used by the debugger to see that it really just moves through the past and when it returns mMoreIcon == null.
Well, especially since another ImageView works.
Has anyone seen this before or had any ideas?
Java code: Class is a descendant of RelativeLayout
@Override protected void onFinishInflate() { super.onFinishInflate(); mText1 = (TextView) findViewById(R.id.text1); mText2 = (TextView) findViewById(R.id.text2); mIcon1 = (ImageView) findViewById(R.id.icon1); mIcon2 = (ImageView) findViewById(R.id.icon2);
XML Code:
<ImageView android:id="@+id/icon1" style="@style/SuggestionIcon1" android:scaleType="centerInside" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_alignParentBottom="true" /> <ImageView android:id="@+id/more_icon1" style="@style/MoreIcon2" android:scaleType="centerInside" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_alignParentBottom="true" android:visibility="gone" /> <ImageView android:id="@+id/icon2" style="@style/SuggestionIcon2" android:scaleType="centerInside" android:layout_toLeftOf="@id/more_icon1" android:layout_alignParentTop="true" android:layout_alignParentBottom="true" android:visibility="gone" />
thanks
source share