I looked for this Null pointer exception because of getTag with Spinners and it has been a while
<p>It`s been few days that I want to implement a ListView containing Spinners. I am really new to android, so going from forum to forum,  I managed to make something work.
The only problem I have is the spinners when scrolling down on my real device,  their values are lost or behave weirdly (sometimes they are reset, some other time the last element takes the value of the first one ..etc)
When I read about that I found out, that android recycles views, so I am trying to use this concept.
Could you please either show me the right approach, or tell me what is the wrong thing I am doing.
The error I get is the following:
04-27 19:43:09.649: E/AndroidRuntime(7530): java.lang.NullPointerException
04-27 19:43:09.649: E/AndroidRuntime(7530):     at com.example.mysqlconnection.MyCustomeArrayAdapter.getView(MyCustomeArrayAdapter.java:106)</p>

<p>Where line 106 corresponds to:
holder.Spin.setSelection((Integer) (holder.Spin.getTag()));</p>

<p>Thank you very much.</p>

<p>list_item.xml

    android:orientation="horizontal" ></p>

<pre><code>&lt;!-- Product id (pid) - will be HIDDEN - used to pass to other activity --&gt;
&lt;TextView
    android:id="@+id/pid"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:visibility="gone" /&gt;   

&lt;!-- Name Label --&gt;
&lt;TextView
    android:id="@+id/name"
    android:textIsSelectable="true"        
    android:layout_width="0dip"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:paddingTop="6dip"
    android:paddingLeft="6dip"
    android:textSize="17sp"
    android:textStyle="bold"/&gt; 

&lt;Spinner
    android:id="@+id/presence"          
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:entries="@array/presence_list"
    android:prompt="@string/presence_prompt"/&gt; 
</code></pre>

<p></p>

<p>public class MyCustomeArrayAdapter extends ArrayAdapter> {  </p>

<pre><code>private static final String TAG_PID = "EnfantId";
private static final String TAG_NOM = "Prenom";

HashMap&lt;String, String&gt; hm = new HashMap&lt;String, String&gt;();      
SpinnerContent data[] = null;    
int[] anArray;

Context context; 

int layoutResourceId;
ArrayList&lt;HashMap&lt;String, String&gt;&gt; localList;
LayoutInflater inflater;

public MyCustomeArrayAdapter(Context pContext,  int layoutResourceId, ArrayList&lt;HashMap&lt;String, String&gt;&gt; list) {
    super(pContext, layoutResourceId, list);

    this.context = pContext;
    this.layoutResourceId = layoutResourceId;

    this.localList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
    this.localList.addAll(list);
    inflater = (LayoutInflater)    context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    data = new SpinnerContent[20];
    anArray = new int[20];

}
</code></pre>

<p>@Override 
public View getView(final int position, View convertView, ViewGroup parent) {</p>

<pre><code>   View row = null;   
   final SpinnerHolder holder;     

   if(convertView == null)
    {                   
        row = inflater.inflate(layoutResourceId, null);

        holder = new SpinnerHolder();

        holder.name = (TextView)row.findViewById(R.id.name);
        holder.pid = (TextView)row.findViewById(R.id.pid);
        holder.Spin = (Spinner)row.findViewById(R.id.presence);
        holder.Spin.setOnItemSelectedListener(new OnItemSelectedListener(){
            @Override
            public void onItemSelected(AdapterView&lt;?&gt; parentView, View selectedItemView, int SpinPosition, long id) {

                holder.Spin.setTag(SpinPosition);
            }

            @Override
            public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
                // TODO Auto-generated method stub
            }   
        });

        row.setTag(holder);
    }
    else
    {
        row = convertView;
        holder = (SpinnerHolder)row.getTag();
    }

   hm = localList.get(position);

   holder.pid.setText(hm.get(TAG_PID));
   holder.name.setText(hm.get(TAG_NOM));     

   holder.Spin.setSelection((Integer) (holder.Spin.getTag()));
   return row;
}

private class SpinnerHolder
{
    TextView name;
    TextView pid;
    Spinner Spin;
}
</code></pre>

<p>}</p>
