【问题标题】:Android cannot serialize byte[] recieved from compressed BMPAndroid 无法序列化从压缩 BMP 收到的字节 []
【发布时间】:2011-06-26 23:26:44
【问题描述】:

代码

Bitmap bmp = (Bitmap)extras.get("data");
ByteArrayOutputStream out = new ByteArrayOutputStream();
bmp.compress(CompressFormat.JPEG, 100, out);
byte[] raw = out.toByteArray();
PassToWebservice(raw); //error

PassToWebservice(byte[] ba)
{
   SoapObject envelope...
   envelope.addProperty("base64bytes", ba);
   ...
   transport.call(ACTION, envelope);
   envelope.getResponse() //error: IOException cannot serialize...
}

问题
当我将压缩图像传递给我的 web 服务时,我得到一个运行时异常,上面写着“无法序列化 [B@47bcb6c8 ...”我看不清楚,谁能明白为什么上面的(伪)代码不起作用?如果它有帮助,在 web 服务服务器端,当服务器将传递的字节写入文件(使用 .Net IO.File.WriteAllBytes)时,似乎会发生异常

堆栈跟踪

【问题讨论】:

  • 不确定我是否完全理解这个问题。异常消息表明它无法序列化字节 [],即您的字节没有到达服务器。你能提供一个堆栈跟踪吗?
  • 它看起来像是在夸大请求并且尚未发送出去。我有 ksoap2 的 Jar 而不是源代码,所以我不能太确定。找到源代码可能会有所帮助。

标签: android web-services serialization bitmap android-ksoap2


【解决方案1】:

我需要这样做:

MarshalBase64 marshal;
marshal.register(envelope);

【讨论】:

  • @Nital 我很抱歉这个问题是很久以前的,我不明白。
【解决方案2】:

SoapSerializationEnvelope 信封 = 新 SoapSerializationEnvelope(SoapEnvelope.VER11);

        new MarshalBase64().register(envelope);   // this is will over Cannot serialize: [B@f034108 

        envelope.dotNet = true;
        //Set output SOAP object
        envelope.setOutputSoapObject(request);
        //Create HTTP call object
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

        try {
            androidHttpTransport.call(SOAPACTION, envelope);
            SoapObject response = (SoapObject) envelope.getResponse();

【讨论】:

    猜你喜欢
    • 2017-10-10
    • 1970-01-01
    • 2012-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多