Cursor appu=X.getsomething();
               if (appu.getCount() > 0)
                  {
                   if  (appu.moveToFirst())
                   {
                     do {
                             String uname = appu.getString(appu.getColumnIndex("content_id"));
                             String ax= appu.getString(appu.getColumnIndex("content"));
                             String unknown =url + ax;
                              t1.append("\n");
                               t1.append(unknown);
                               //downloadimages(unknown,uname); 
                        }while (appu.moveToNext());
                   } 
                   X.close();
这是我从数据库中获取一些结果的代码,通过这个结果,我创建了一个包含图像的 url,当我尝试运行该downloadimages()函数时,我想为每个光标结果下载该图像,我的应用程序总是崩溃我不知道为什么......但是当我在没有它的情况下运行代码时,它运行完美。
下载图片方法
      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 | DownloadManager.Request.NETWORK_MOBILE);
              request.setAllowedOverRoaming(false);
             request.setDescription("Android Data download using DownloadManager.");
           request.setDestinationInExternalFilesDir(getApplicationContext(),Environment.DIRECTORY_DOWNLOADS,v1 + ".jpg");
              downloadManager.enqueue(request);     
        }
请告诉我我做错了什么???
 Cursor appu=X.getsomething();
               if (appu.getCount() > 0)
                  {
                   if  (appu.moveToFirst())
                   {
                     do {
                             String uname = appu.getString(appu.getColumnIndex("content_id"));
                             String ax= appu.getString(appu.getColumnIndex("content"));
                             imageid.add(uname);
                             String unknown =url + ax;
                             imagepath.add(unknown);
                             // t1.append("\n");
                               //t1.append(unknown);
                        }while (appu.moveToNext());
                   } 
                   X.close();
                  }}
            this.getitdone();
            }
        public void getitdone()
        {
            int b=imagepath.size();
            for(int i=1;i<=b;i++)
            {
                 String extra=imagepath.get(i).toString();
                 String extra2=imageid.get(i).toString();
                downloadimages(extra,extra2);
            }
        }
现在我正在这样做,并且运行良好