2013-02-21 31 views
-1

我想从我时,应用程序通过这个代码下载管理器类尝试下载多个文件时崩溃?

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);  

     } 

当我运行该应用程序第一次下载发生,但在此之后,应用程序did'nt打开应用程序崩溃连接到Internet网络上下载图片我检查了dowloaded文件还:

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 

回答

0

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

然后错误是IndexOutOfBoundsException,所以你尝试用较少的图像,例如10或20?并在第一个10恢复后再运行?