how to set images in gridview using SDCard
<p>I want to set images in the grid view from the SDCard. I have made gridview using static images.But for the SDCard when i run my project it shows error for the nullpointer.</p>

<pre><code>public class MyGridViewSDActivity extends Activity{
    private Cursor cursor;
    private int columnIndex;
    ImageAdapter adapter;
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mygridacti);

        String[] projection = {MediaStore.Images.Thumbnails._ID};
        cursor = managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, projection, null, null, MediaStore.Images.Thumbnails._ID);
        columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);

        GridView gView = (GridView)findViewById(R.id.grdvw);
        gView.setAdapter(new ImageAdapter(this));
        adapter.notifyDataSetChanged();

        gView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position,
                    long id) {
                // TODO Auto-generated method stub
                String[] projection = {MediaStore.Images.Thumbnails.DATA};
                cursor = managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, projection, null, null, MediaStore.Images.Thumbnails.IMAGE_ID);
                columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
                cursor.moveToPosition(position);
                String imagePath = cursor.getString(columnIndex);
            }
        });
    }
}

class ImageAdapter extends BaseAdapter{
    Cursor cursor;
    ImageView imageview;
    Context mContext;
    int columnIndex;
    public ImageAdapter(Context adapter){
        mContext = adapter;
    }

    public ImageAdapter(OnClickListener onClickListener) {
        // TODO Auto-generated constructor stub

    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return cursor.getCount();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        if(convertView == null){
            imageview = new ImageView(mContext);
            cursor.moveToPosition(position);
            int imageID = cursor.getInt(columnIndex);
            imageview.setImageURI(Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, ""+imageID));
            imageview.setScaleType(ImageView.ScaleType.FIT_CENTER);
            imageview.setPadding(8, 8, 8, 8);
            imageview.setLayoutParams(new GridView.LayoutParams(100, 100));
        }
        else{
            imageview = (ImageView)convertView;
        }
        return imageview;
    }
}
</code></pre>

<p>Error:</p>

<pre><code>07-12 12:07:30.449: ERROR/AndroidRuntime(2231): FATAL EXCEPTION: main
07-12 12:07:30.449: ERROR/AndroidRuntime(2231): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myworkspace/com.myworkspace.MyGridViewSDActivity}: java.lang.NullPointerException
07-12 12:07:30.449: ERROR/AndroidRuntime(2231):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
07-12 12:07:30.449: ERROR/AndroidRuntime(2231):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
07-12 12:07:30.449: ERROR/AndroidRuntime(2231):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-12 12:07:30.449: ERROR/AndroidRuntime(2231):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
07-12 12:07:30.449: ERROR/AndroidRuntime(2231):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-12 12:07:30.449: ERROR/AndroidRuntime(2231):     at android.os.Looper.loop(Looper.java:123)
07-12 12:07:30.449: ERROR/AndroidRuntime(2231):     at android.app.ActivityThread.main(ActivityThread.java:3647)
07-12 12:07:30.449: ERROR/AndroidRuntime(2231):     at java.lang.reflect.Method.invokeNative(Native Method)
07-12 12:07:30.449: ERROR/AndroidRuntime(2231):     at java.lang.reflect.Method.invoke(Method.java:507)
07-12 12:07:30.449: ERROR/AndroidRuntime(2231):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-12 12:07:30.449: ERROR/AndroidRuntime(2231):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-12 12:07:30.449: ERROR/AndroidRuntime(2231):     at dalvik.system.NativeStart.main(Native Method)
07-12 12:07:30.449: ERROR/AndroidRuntime(2231): Caused by: java.lang.NullPointerException
07-12 12:07:30.449: ERROR/AndroidRuntime(2231):     at com.myworkspace.ImageAdapter.getCount(MyGridViewSDActivity.java:64)
07-12 12:07:30.449: ERROR/AndroidRuntime(2231):     at android.widget.GridView.setAdapter(GridView.java:131)
07-12 12:07:30.449: ERROR/AndroidRuntime(2231):     at com.myworkspace.MyGridViewSDActivity.onCreate(MyGridViewSDActivity.java:31)
07-12 12:07:30.449: ERROR/AndroidRuntime(2231):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-12 12:07:30.449: ERROR/AndroidRuntime(2231):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
07-12 12:07:30.449: ERROR/AndroidRuntime(2231):     ... 11 more
</code></pre>
