How to print my file?
<p>Hi how to print file list...now I trying to print my file list...but I am its not printing...please help me....</p>

<p>This is my coding:</p>

<pre><code>package ImageViewExample.ImageViewExample;

import java.io.File;
import java.util.ArrayList;
import android.R.string;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.GridView;
//import android.widget.GridView; 
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;

public class ImageViewExample extends Activity {
 /** Called when the activity is first created. */
private Cursor imagecursor, actualimagecursor;
private int image_column_index, actual_image_column_index;
GridView imagegrid;
private int count;
      @Override
      public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      init_phone_image_grid();
      }
      private void init_phone_image_grid() {
      String[] img = { MediaStore.Images.Thumbnails._ID };
      imagecursor = managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, 
      img, null,null, 
                    MediaStore.Images.Thumbnails.IMAGE_ID + "");
      System.out.println("cursor"+managedQuery(MediaStore.Images
      .Thumbnails.EXTERNAL_CONTENT_URI, img, null,null, 
                MediaStore.Images.Thumbnails.IMAGE_ID + ""));
      image_column_index =    
      imagecursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
      System.out.println("index"+imagecursor.getColumnIndexOrThrow(MediaStore
      .Images.Thumbnails._ID));
      count = imagecursor.getCount();
      System.out.println("image"+count);
      imagegrid = (GridView) findViewById(R.id.PhoneImageGrid);
      imagegrid.setAdapter(new ImAdapterh(this));

      imagegrid.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView parent, View v,int position, long id) 
      { 
      System.gc();
      String[] proj = { MediaStore.Images.Media.DATA };
      actualimagecursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 
      proj,null, null, null);
     // System.out.println("doubt"+managedQuery(MediaStore
     .Images.Media.EXTERNAL_CONTENT_URI, proj,null, null, null));
      actual_image_column_index = 
      actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
      actualimagecursor.moveToPosition(position);

                  String i = actualimagecursor.getString(actual_image_column_index);

                  System.gc();
                  Intent intent = new Intent(getApplicationContext(), ViewImage.class);
                  intent.putExtra("filename", i);
                  startActivity(intent);
            }
      });
    }


   public class ImAdapterh extends BaseAdapter{
   File dir=new File(Environment.getExternalStorageDirectory(),"/myImages/");
   int count=dir.list().length; 
   String[] fileNames = dir.list();
   private Context mContext;

   public ImAdapterh(Context c) {
       mContext = c;

   }

   public int getCount() {
       return count;
              }
   public Object getItem(int position) {
               return position;
                         }

   public long getItemId(int position) {
       return 0;
              }

     // create a new ImageView for each item referenced by the Adapter
     public View getView(int position, View convertView, ViewGroup parent) {
       ImageView imageView = null;        

      for(String bitmapFileName : fileNames)
      {
          if (convertView == null) 
          {  // if it's not recycled, initialize some attributes
              imageView = new ImageView(mContext);
              imageView.setLayoutParams(new Gallery.LayoutParams(85, 85));
              imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
              imageView.setPadding(8, 8, 8, 8);                   
              Bitmap bmp = BitmapFactory.decodeFile(dir.getPath() + "/" + 
           bitmapFileName);
              imageView.setImageBitmap(bmp);  
           }else 
           {
           imageView = (ImageView) convertView;            

           }
       }            return imageView;

       }

   }}
</code></pre>

<p>I wish to print my file list:</p>

<pre><code> File dir=new File(Environment.getExternalStorageDirectory(),"/myImages/");
   int count=dir.list().length; 
   String[] fileNames = dir.list();
</code></pre>

<p>logcat error:</p>

<pre><code>05-05 22:39:42.147: DEBUG/dalvikvm(739): GC_EXTERNAL_ALLOC freed 1035 objects / 68800 
bytes in 141ms
05-05 22:39:42.497: DEBUG/dalvikvm(739): GC_EXTERNAL_ALLOC freed 418 objects / 217344 
bytes in 118ms
05-05 22:39:42.568: DEBUG/AndroidRuntime(739): Shutting down VM
05-05 22:39:42.578: WARN/dalvikvm(739): threadid=1: thread exiting with uncaught 
exception (group=0x4001d800)
05-05 22:39:42.608: ERROR/AndroidRuntime(739): FATAL EXCEPTION: main
05-05 22:39:42.608: ERROR/AndroidRuntime(739): java.lang.ClassCastException:    
android.widget.Gallery$LayoutParams
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at    
android.widget.GridView.onMeasure(GridView.java:934)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at  
android.view.View.measure(View.java:8171)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at 
android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at 
android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at 
android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at 
android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at 
android.view.View.measure(View.java:8171)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at 
android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at 
android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at 
android.view.View.measure(View.java:8171)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at 
android.widget.LinearLayout.measureVertical(LinearLayout.java:526)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at    
android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at 
android.view.View.measure(View.java:8171)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at 
android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at 
android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at 
android.view.View.measure(View.java:8171)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at 
android.view.ViewRoot.performTraversals(ViewRoot.java:801)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at 
android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at 
android.os.Handler.dispatchMessage(Handler.java:99)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at   
android.os.Looper.loop(Looper.java:123)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at  
android.app.ActivityThread.main(ActivityThread.java:4627)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at 
java.lang.reflect.Method.invokeNative(Native Method)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at 
java.lang.reflect.Method.invoke(Method.java:521)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-05 22:39:42.608: ERROR/AndroidRuntime(739):     at 
dalvik.system.NativeStart.main(Native Method)
05-05 22:39:42.638: WARN/ActivityManager(64):   Force finishing activity 
ImageViewExample.ImageViewExample/.ImageViewExample
05-05 22:39:43.157: WARN/ActivityManager(64): Activity pause timeout for 
HistoryRecord{43fb0c88 ImageViewExample.ImageViewExample/.ImageViewExample}
</code></pre>
