0

私のAndroidアプリケーションでは、致命的な例外が発生しています。サムネイル、画像の名前、画像のサイズなどの画像情報をリストしています。しかし、その例外の下でコードを実行しようとしたとき。ここにコードがあります-

 public class ImportFile<Context> extends ListActivity {
 String names[];
 Bitmap bb[];
 long size1[];
 Intent i;
  private String myFile;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mylist); 

        File file = new File(Environment.getExternalStorageDirectory()
            + File.separator
            + "gallery" //folder name
        );
        if (!file.exists()) {
            file.mkdirs();
        }

        setListAdapter(new IconicAdapter());

    }

    class IconicAdapter extends ArrayAdapter<String> {
        IconicAdapter() {
            super(ImportFile.this, R.layout.row, R.id.lable, names);
        }

        public View getView(int position,View convertview,ViewGroup parent){
            View row=super.getView(position, convertview, parent);
            ImageView icon=(ImageView)row.findViewById(R.id.icon);

        icon.setImageBitmap(bb[position]);
        TextView size=(TextView) row.findViewById(R.id.size);

        size.setText(size1[position]+"");
        return row;
        }

    }

    //read from sdcard
    private void getSD() {
        List<String> item = new ArrayList<String>();
        File f = new File("/sdcard/download");
        File[] files = f.listFiles();

        int j=0;
        for(int i = 0; i < files.length; i++) {
            File file = files[i];
            //take the file name only
            long size = file.length()/1024;

            myFile = file.getPath().substring(file.getPath().lastIndexOf("/")+1,file.getPath().length()).toLowerCase(); 

            if(myFile.endsWith(".jpeg")||myFile.endsWith(".png")|| myFile.endsWith(".gif") || myFile.endsWith(".jpg"))
            {
                names[j]=myFile;

                size1[j]=size;

                Bitmap b=ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(file.getPath()), 50,50);
                bb[j]=b;
                j++;
            item.add(b +myFile+"             "+"Size:"+size+" KB" );

            }

        }

    }
    }

以下は例外です -

02-14 18:00:44.267: E/AndroidRuntime(909): FATAL EXCEPTION: main
02-14 18:00:44.267: E/AndroidRuntime(909): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.zproject/com.my.zproject.ImportFile}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
02-14 18:00:44.267: E/AndroidRuntime(909):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
02-14 18:00:44.267: E/AndroidRuntime(909):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-14 18:00:44.267: E/AndroidRuntime(909):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-14 18:00:44.267: E/AndroidRuntime(909):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-14 18:00:44.267: E/AndroidRuntime(909):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-14 18:00:44.267: E/AndroidRuntime(909):  at android.os.Looper.loop(Looper.java:123)
02-14 18:00:44.267: E/AndroidRuntime(909):  at android.app.ActivityThread.main(ActivityThread.java:4627)
02-1 4 18:00:44.267: E/AndroidRuntime(909):     at java.lang.reflect.Method.invokeNative(Native Method)
02-14 18:00:44.267: E/AndroidRuntime(909):  at java.lang.reflect.Method.invoke(Method.java:521)
02-14 18:00:44.267: E/AndroidRuntime(909):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-14 18:00:44.267: E/AndroidRuntime(909):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-14 18:00:44.267: E/AndroidRuntime(909):  at dalvik.system.NativeStart.main(Native Method)
  02-14 18:00:44.267: E/AndroidRuntime(909): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

02-14 18:00:44.267: E/AndroidRuntime(909): at android.app.ListActivity.onContentChanged(ListActivity.java:245)
  02-14 18:00:44.267: E/AndroidRuntime(909): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201)
  02-14 18:00:44.267: E/AndroidRuntime(909): at   android.app.Activity.setContentView(Activity.java:1647)
  02-14 18:00:44.267: E/AndroidRuntime(909): at com.my.zproject.ImportFile.onCreate(ImportFile.java:33)

ここにrow.xmlがあります-

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >


<ImageView 
    android:id="@+id/icon"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_gravity="center_vertical"
  android:padding="2dip"

    />

<LinearLayout 
    android:layout_width="fill_parent"
 android:layout_height="wrap_content"
android:orientation="vertical"
    >
    <TextView 
        android:id="@+id/lable"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        />
     <TextView 
        android:id="@+id/size"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
     </LinearLayout>
   </LinearLayout>

ここに mylist.xml

   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
   <ListView 
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
    android:id="@+id/list" >
  </ListView>
   </LinearLayout>
4

1 に答える 1

1

ListViewのIDをに変更してみてください@android:id/list

于 2013-02-14T12:59:14.897 に答える