无法从SD卡中删除文件

时间:2013-04-06 09:37:54

标签: android android-file

我正在尝试从我的SD卡中删除文件,但我收到此错误

04-06 11:36:25.762: W/System.err(4214): java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
04-06 11:36:25.782: W/System.err(4214):     at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
04-06 11:36:25.782: W/System.err(4214):     at java.util.ArrayList.get(ArrayList.java:304)
04-06 11:36:25.782: W/System.err(4214):     at com.myapp.functions.DownloadedAlbumLazyAdapter$1$1.onClick(DownloadedAlbumLazyAdapter.java:96)
04-06 11:36:25.782: W/System.err(4214):     at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
04-06 11:36:25.792: W/System.err(4214):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-06 11:36:25.792: W/System.err(4214):     at android.os.Looper.loop(Looper.java:137)
04-06 11:36:25.792: W/System.err(4214):     at android.app.ActivityThread.main(ActivityThread.java:4440)
04-06 11:36:25.792: W/System.err(4214):     at java.lang.reflect.Method.invokeNative(Native Method)
04-06 11:36:25.792: W/System.err(4214):     at java.lang.reflect.Method.invoke(Method.java:511)
04-06 11:36:25.792: W/System.err(4214):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
04-06 11:36:25.792: W/System.err(4214):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
04-06 11:36:25.792: W/System.err(4214):     at dalvik.system.NativeStart.main(Native Method)

以下是我删除文件的代码:

dbHelper = new DatabaseHelper(activity);
                            dbHelper.openDB();
                            try {
                                ArrayList<Songs> downSongs = new ArrayList<Songs>();
                                Log.v("--", downSongs.size()+"");
                                downSongs = dbHelper
                                        .getDownloadedSongsForAlbum(data.get(
                                                position).getTAG_ID());
                                for (int i = 0; i < downSongs.size(); i++) {
                                    File file = new File(downSongs.get(i)
                                            .getSONG_MP3());
                                    Log.v("--", downSongs.get(i).getSONG_MP3());
                                    Log.v("--",file.delete()+"");
                                    dbHelper.removeDownloadedAlbum(data.get(i)
                                            .getTAG_ID());
                                    dbHelper.removeDownloadedSong(downSongs
                                            .get(i).getSONG_MP3());
                                    dbHelper.closeDB();

以及从db获取下载歌曲的功能:

public ArrayList<Songs> getDownloadedSongsForAlbum(String albumID){
        Cursor c = database.rawQuery("SELECT * FROM downloaded_songs " + "WHERE "
                + "album_id" + " = '" + albumID + "'", null);
        ArrayList<Songs> songs=new ArrayList<Songs>();
        if (c != null)
            if (c.moveToFirst()) {
                do {
                    String title = c.getString(c.getColumnIndex("title"));
                    String artist = c.getString(c.getColumnIndex("artist"));
                    String mp3 = c.getString(c.getColumnIndex("mp3"));
                    String mp4 = c.getString(c.getColumnIndex("mp4"));
                    String thumb = c.getString(c.getColumnIndex("thumb"));
                    songs.add(new Songs(title, artist, mp3, mp4, "http://mylink.com/cover_image/"+thumb));
                } while (c.moveToNext());
            }
        return songs;
    }

0 个答案:

没有答案