下载管理器类在尝试下载多个文件时崩溃了?

时间:2013-02-21 12:37:22

标签: android performance android-download-manager

当我的应用通过此代码连接到互联网时,我正尝试从网上下载图片

public void downloadimages(String url,String filename)
        {
          String ur1=url,v1=filename;
          downloadManager = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
          Uri Download_Uri = Uri.parse(ur1);
          DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
          request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
          request.setAllowedOverRoaming(false);
          request.setDescription("Android Data download using DownloadManager.");
          request.setDestinationInExternalFilesDir(getApplicationContext(),Environment.DIRECTORY_DOWNLOADS,v1 + ".jpg");
          downloadManager.enqueue(request);     

        }

当我运行应用程序第一次下载发生但应用程序崩溃后应用程序没有打开我正在检查已下载的文件:

String path = "/mnt/sdcard/Android/data/com.example.webdata/files/Download/" + extra2 + ".jpg";
                 tt1.append(path);
                 File f = new File(path);
                  if(f.exists())
                  { 
                    //Toast.makeText(getApplicationContext(), "File already exists....",
                        //  Toast.LENGTH_SHORT).show(); 
                  }
                  else
                  {
                   downloadimages(extra,extra2);
                  }

如果文件先前已下载,则下次不应下载,但我的应用程序崩溃,我不知道为什么有任何帮助人......... 这是我的logcat输出: -

02-21 18:00:41.547: E/AndroidRuntime(23964): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.webdata/com.example.webdata.MainActivity}: java.lang.IndexOutOfBoundsException: Invalid index 1088, size is 1088

1 个答案:

答案 0 :(得分:0)

你能告诉我们代码MainActivity类,因为看起来错误来自这个类。

然后错误是IndexOutOfBoundsException,所以您尝试使用较少的图像,例如10或20吗?当前10个被恢复时运行?

相关问题