0

我已将我的 DB 文件转换为字节数组,并希望将其传递给我的 Web 服务以便保存在服务器上。我的数据库大小为 5 mb,但是在添加到 soap_request 时,它给出了内存不足的异常......我附上我的代码如下

File file = new File(filePath);
                int size = (int) file.length();
                byte[] bytes = new byte[size];

                Log.v(TAG, "File size in byte ==>"+size);
                try {
                    BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file));
                    buf.read(bytes, 0, bytes.length);
                    buf.close();
                    Log.v(TAG, "ByteArray = "+bytes.length);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }

                    SoapObject soap_request = new SoapObject(NAMESPACE, METHOD_NAME);
                    fileName = "TraceBaleAndroid_"+UserID+"_"+backupDateTime+".db";
                    Log.v(TAG, "FileName = "+fileName);
                    soap_request.addProperty("_FileName", fileName);

                    soap_request.addProperty("_ByteArray",bytes);
                    soap_request.addProperty("UserID", UserID);

                    Log.v(TAG, "soap_request _FileName= >>"+soap_request.getProperty(0));
                    //Log.v(TAG, "soap_request _ByteArray= >>"+soap_request.getProperty(1));
                    Log.v(TAG, "soap_request UserID= >>"+soap_request.getProperty(2));

                    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                    new MarshalBase64().register(envelope);
                    envelope.setOutputSoapObject(soap_request);
                    envelope.dotNet = true;

                    Log.v(TAG,"Calling webservice....");
                    androidHttpTransportSE = new HttpTransportSE(URL);
                    androidHttpTransportSE.debug = true;
                    androidHttpTransportSE.call(SOAP_ACTION, envelope);

                    Log.v(TAG,"Getting result from webservice....");
                    SoapObject result = (SoapObject) envelope.bodyIn;
                    JSONObject response = new JSONObject(result.getProperty(0).toString());
                    Log.v(TAG, "Web Response...." + response.get(" Result "));

                    if (response.get(" Result ").equals("Uploading DataBase Backup To Server successfully"))
                    {
                        flag = true;
                        Log.v(TAG, "Database is uploaded .........");
                    }

            } catch (Exception e) {
                e.printStackTrace();
            }
            finally 
            {
                androidHttpTransportSE.reset();

            } 
4

1 回答 1

0

带有 5MB 数据的 SOAP 请求对我来说真的很奇怪。但是,如果您确实确定需要这个,请查看以下问题的答案:如何增加 android 应用程序的堆大小? 所有这些建议也适用于您的情况。

于 2013-02-13T08:02:03.933 回答