Exception in GridView
<p>I was trying a sample program to understand the behavior of the dynamic <code>GridView</code>. When I tried to execute the program I got a run-time exception at <code>texts.setText(str[position]);</code> in the .java file. </p>

<h2>.java</h2>

<pre><code>package GridView_dynamic.grid;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;

public class GridView_dynamic extends Activity {
    /** Called when the activity is first created. */
 TextView select; 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        select = (TextView)findViewById(R.id.text);
        GridView grid = (GridView)findViewById(R.id.grid);
        grid.setAdapter(new my_Adapter(this));
    }
    public class my_Adapter extends BaseAdapter{
     String[] str = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N"};
     public Context context;
     public my_Adapter(Context context) {
      // TODO Auto-generated constructor stub
      this.context = context;
     }
     @Override
     public int getCount() {
      // TODO Auto-generated method stub
      return str.length;
     }
     @Override
     public Object getItem(int position) {
      // TODO Auto-generated method stub
      return null;
     }
     @Override
     public long getItemId(int position) {
      // TODO Auto-generated method stub
      return 0;
     }
     @Override
     public View getView(int position, View convertView, ViewGroup parent) {
      // TODO Auto-generated method stub
      if(convertView == null){
       Toast.makeText(context,"convertView is NULL", Toast.LENGTH_LONG).show();
      }
      TextView texts;
      texts = (TextView)convertView;
      //texts = (TextView)findViewById(R.id.text);
      texts.setText(str[position]);
      return texts;
     }

    }
}
</code></pre>

<h2>main.xml</h2>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
&gt;
&lt;TextView 
android:id="@+id/text"
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:background="#0000aa"
android:textColor="#00aa00"
/&gt;
&lt;GridView
android:id="@+id/grid"
android:layout_width="fill_parent" 
android:layout_height="match_parent"
android:background="#aaaaaa"
/&gt;
&lt;/LinearLayout&gt;
</code></pre>
