1

我在一张桌子上有两张图片。现在我必须将它们都作为 blob 存储在 SQLite 中。但我正在努力寻找一种在两个 URL 的情况下获取它的方法。如果是一个我可以解决它。谁能建议我如何解决这个问题?

我正在尝试的代码是:

private void callInsertion(String bid, String bbookId,String bname, String image1, String image2, String bdesc) throws IOException {
// TODO Auto-generated method stub

     DefaultHttpClient mHttpClient = new DefaultHttpClient();
     HttpGet mHttpGet1 = new HttpGet(image1);
     HttpGet mHttpGet2 = new HttpGet(image2);
     HttpResponse mHttpResponse = mHttpClient.execute(mHttpGet1,mHttpGet2);

     if (mHttpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) 
     {
         HttpEntity entity = mHttpResponse.getEntity();
         if ( entity != null) 
         {
             insertData(bid,bbookId,bname,EntityUtils.toByteArray(entity),EntityUtils.toByteArray(entity),bdesc);
         }
     }
}

但是我在客户端执行时遇到错误。

4

1 回答 1

1

试着变成这样!!

         private void callInsertion(String bid, String bbookId,String bname, String image1, String image2, String bdesc) throws IOException {
            // TODO Auto-generated method stub

        byte[] FirstImage = null;
        byte[] SecondImage = null;
        DefaultHttpClient mHttpClient1 = new DefaultHttpClient();
        DefaultHttpClient mHttpClient2 = new DefaultHttpClient();
        HttpGet mHttpGet1 = new HttpGet(image1);
        HttpGet mHttpGet2 = new HttpGet(image2);
        HttpResponse mHttpResponse1 = mHttpClient1.execute(mHttpGet1);
        HttpResponse mHttpResponse2 = mHttpClient2.execute(mHttpGet2);
        Log.i("calling112221","______________");
        if (mHttpResponse1.getStatusLine().getStatusCode() == HttpStatus.SC_OK) 
        {
               HttpEntity entity1 = mHttpResponse1.getEntity();
               FirstImage = EntityUtils.toByteArray(entity1);
               Log.i("calling11111111","______________");
        }
        if (mHttpResponse2.getStatusLine().getStatusCode() == HttpStatus.SC_OK) 
        {
                HttpEntity entity2 = mHttpResponse2.getEntity();
                SecondImage = EntityUtils.toByteArray(entity2);
                Log.i("calling","______________");
        }

                    insertData(bid,bbookId,bname,FirstImage,SecondImage,bdesc);
        }
于 2012-11-22T07:47:14.053 回答