2017-01-31 10 views
-1

byte arrayを返すWebサービスを作成しました。java.lang.OutOfMemoryError Android SOAPレスポンスバイト配列

私はアンドロイドのアプリケーションからサービスを呼び出し、それがライン上のメモリエラーのうち、私にを与える:それは働く一部のモバイルデバイスでは

androidHttpTransport.call(SOAP_ACTION + WebMethodName, envelope); 

が、一部のモバイルデバイス(おそらくデバイス上RAMが少ない)、メモリエラーが発生します。

お勧めします。

アップデート#2 @Rohit - ここに私のコードは

public static void DownloadFile(String WebMethodName, String ServiceURL) 
{ 
byte[] imgBytes=null; 
SoapObject request = new SoapObject(NAMESPACE, WebMethodName); 

PropertyInfo NameProperty = new PropertyInfo(); 
NameProperty.setName("Name"); 
NameProperty.setValue("TEST"); 
NameProperty.setType(String.class); 
request.addProperty(NameProperty); 

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
envelope.setOutputSoapObject(request); 

HttpTransportSE androidHttpTransport = new HttpTransportSE(ServiceURL,100000); 

try { 
    //On below line I get OOM error 

    androidHttpTransport.call(SOAP_ACTION + WebMethodName, envelope); 
    final SoapPrimitive primitive = (SoapPrimitive) envelope.getResponse(); 
    if (primitive == null) 
    { 
     imgBytes=null; 
    } 
    else 
    { 
     final String imgData = primitive.toString(); 

     if (imgData != "") 
     { 
      imgBytes = Base64.decode(imgData, Base64.DEFAULT); 
      String s = new String(imgBytes); 

      String filePath = android.os.Environment.getExternalStorageDirectory() +"/TestDirectory/Test.apk" ; 

      File file = new File(filePath); 
      file.getParentFile().mkdirs(); 
      file.createNewFile(); 

      BufferedOutputStream objectOut = new BufferedOutputStream(new FileOutputStream(file)); 
      objectOut.write(imgBytes); 
      objectOut.close(); 
      } 

     } 
     else 
     { 
      Log.w("ImgData", "Image data is null"); 
     } 
    } 
} catch (Exception e) { 
    e.printStackTrace(); 
    Log.w("ImgData", "Error :" + e.getMessage()); 
} 

} 

でアップデート#3

@parik dhakan

私は= "true" をlargeHeapを試してみましたが、同じエラーを得ました。また、largeHeap = "true"を使用することはお勧めできません。 ご返信ありがとうございます。

+0

<application android:largeHeap="true"> 

を追加しようとする正確なissuseをチェックするようにコードを入力してください。 – Rohit

+0

@Rohit - 私は自分の質問にコードを追加しました。確認して元に戻してください。 – Vito

答えて

0

はマニフェスト

関連する問題