Note that there are some explanatory texts on larger screens.

plurals
  1. POImageView throwing NullReferenceException on Inflated LinearLayout
    primarykey
    data
    text
    <p>I'm having some problems with a NullReferenceExcpetion on an ImageView after I use a LayoutInflater to inflate the parent layout. As you can see in the Layout XML below, I have two TextView's and one ImageView. I can reference both of the TextViews just fine, but not the ImageView.</p> <p>When I drilldown into the properties of the inflated layout's child views, I see that the <strong>mID</strong> property of both the TextViews are correct, however the <strong>mID</strong> of the ImageView is -1</p> <p>Would anybody have any idea why only the ImageView is coming up as NULL? I'm sure it's something stupid, but I just can't figure it out. I've also recreated the Layout XML file, cleaned my project, etc.</p> <p>Thanks in advance!!</p> <p><strong>Layout XML:</strong> </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"&gt; &lt;LinearLayout android:layout_width="120px" android:layout_height="wrap_content" android:orientation="vertical"&gt; &lt;TextView android:id="@+id/weather_forecast_day" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:textStyle="bold"/&gt; &lt;ImageView android:id="@+id/weather_forecast_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal"/&gt; &lt;TextView android:id="@+id/weather_forecast_temps" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:textStyle="bold"/&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>Code:</strong> </p> <pre><code>mForecastItem = (LinearLayout)View.inflate(WeatherLookup.this, R.layout.weather_forecast_item, null); ((ImageView)mForecastItem.findViewById(R.id.weather_forecast_icon)) .setImageDrawable(getResources().getDrawable(R.drawable.weather_sunny)); ((TextView)mForecastItem.findViewById(R.id.weather_forecast_day)) .setText(forecast.DayOfWeek); ((TextView)mForecastItem.findViewById(R.id.weather_forecast_temps)) .setText(forecast.High + "\u2109 / " + forecast.Low + "\u2109"); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload