Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid ListView NullPointerException when inflating View
    text
    copied!<p>i have a ListView with a custom row: <strong>detail_row1.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="fill_parent" android:orientation="horizontal" android:layout_height="wrap_content" android:padding="6dip" **android:background="@drawable/item_background_selector"** ---&gt; line 7 android:id="@+id/detail_linearLayout" &gt; &lt;TextView android:id="@+id/propName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:textSize="16sp" android:textStyle="bold" android:textColor="#000000" android:gravity="center_vertical|left" android:paddingTop="10sp" android:paddingBottom="10sp" android:paddingLeft="4sp" /&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="2" android:id="@+id/propValue" android:textColor="#000000" android:textSize="16sp" android:textStyle="bold" android:paddingTop="10sp" android:paddingBottom="10sp" android:paddingRight="4sp" android:gravity="center_vertical|right" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>my <strong>/drawable/item_background_selector.xml</strong> (SAME if i put it under <strong>/color/item_background_selector.xml</strong> and properly reference it in detail_row1.xml)</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:state_selected="false" android:color="#ACD52B"&gt; &lt;/item&gt; &lt;item android:state_selected="true" android:color="#0094CE"&gt; &lt;/item&gt; &lt;/selector&gt; </code></pre> <p>when I try to inflate this view in my ListAdapter:</p> <pre><code>public View getView(int position, View convertView, ViewGroup parent) { View v=convertView; if(v==null) { LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); v=vi.inflate(R.layout.detail_row1, null); **--&gt; NullPointerException** } . . </code></pre> <p>It throws a NullPointerException.</p> <p>This is not the case if i simply remove line 7 (android/background) from detail_row1.xml</p> <p>Any clue / help on why this is happening (fairly new to android)</p> <p>Thanks in advance!</p> <p>(edit) Logcat:</p> <pre><code>**08-24 00:27:53.637: E/AndroidRuntime(15295): FATAL EXCEPTION: main** 08-24 00:27:53.637: E/AndroidRuntime(15295): android.view.InflateException: Binary XML file line #2: Error inflating class &lt;unknown&gt; 08-24 00:27:53.637: E/AndroidRuntime(15295): at android.view.LayoutInflater.createView(LayoutInflater.java:613) 08-24 00:27:53.637: E/AndroidRuntime(15295): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 08-24 00:27:53.637: E/AndroidRuntime(15295): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660) 08-24 00:27:53.637: E/AndroidRuntime(15295): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685) 08-24 00:27:53.637: E/AndroidRuntime(15295): at android.view.LayoutInflater.inflate(LayoutInflater.java:466) 08-24 00:27:53.637: E/AndroidRuntime(15295): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 08-24 00:27:53.637: E/AndroidRuntime(15295): at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 08-24 00:27:53.637: E/AndroidRuntime(15295): at **com.dhomes.steel.DetailActivity$1.getView(DetailActivity.java:101)** </code></pre> <p><strong>(2nd edit)</strong> </p> <p>My listAdapter:</p> <pre><code>lvProperties.setAdapter(new ListAdapter() { //Section section=new Section(); @Override public View getView(int position, View convertView, ViewGroup parent) { View v=convertView; if(v==null) { //LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater vi =(LayoutInflater)DetailActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v=vi.inflate(R.layout.detail_row1, null); } TextView name=(TextView)v.findViewById(R.id.propName); TextView value=(TextView)v.findViewById(R.id.propValue); if(name!=null) { name.setText(section.propNames.get(position)); } if(value!=null) { value.setText(section.propValues.get(position)); } return v; } . . . } </code></pre>
 

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