RuntimeException的:不能序列:错误从Android通过发送KSOAP字节数组的Java应用程序 [英] RunTimeException:cannot serialize: Error to send byte array from android to java application through ksoap

查看:345
本文介绍了RuntimeException的:不能序列:错误从Android通过发送KSOAP字节数组的Java应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用kso​​ap2对于android系统中发送的字节数组我的Java应用程序在Android device.I米,我在使用Axis2创建的Java Web服务来接收字节数组,并创建文件服务器在作进一步处理。

I have to Send Byte Array to my java application From Android device.I m using ksoap2 for that in android and i have created web service in java with axis2 to receive that byte array and create file at server for further processing.

让我给你全部explanation.i我在录音的Andr​​oid设备波形文件,然后将该波形文件需要java应用程序是在server.i创造了一个web服务的Java应用程序中使用Axis2名称定为待发送get_wave_byte这再次到来的字节数组转换到一个波形文件并将其存储在从Android设备我发送波形文件的字节数组,并存储路径get_wave_byte的参数()。

Let me Give you Full explanation.i am Recording a wave file in android device and then that wave file need to be send at java application which is on server.i had created one web service in java application with axis2 name as "get_wave_byte" which converts the incoming byte array in to a wave file again and store it in server.and from android device i am sending wave file as byte array and also the storage path in the argument of get_wave_byte().

因此​​,对于我创建波形文件在android系统之后,我已经创建了在转换的波形文件到字节的波形文件转换在字节数组array.the方法一种方法是如下...

So for that I have created wave file in android and after that i have created one method which converts that wave file in to byte array.the method that converts the wave file in byte array is as follows...

public static byte[] getBytesFromFile(File file) throws IOException {
        InputStream is = new FileInputStream(file);

        // Get the size of the file
        long length = file.length();

        // You cannot create an array using a long type.
        // It needs to be an int type.
        // Before converting to an int type, check
        // to ensure that file is not larger than Integer.MAX_VALUE.
        if (length > Integer.MAX_VALUE) {
            // File is too large
        }

        // Create the byte array to hold the data
        byte[] bytes = new byte[(int)length];

        // Read in the bytes
        int offset = 0;
        int numRead = 0;
        while (offset < bytes.length
               && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
            offset += numRead;
        }

        // Ensure all the bytes have been read in
        if (offset < bytes.length) {
            throw new IOException("Could not completely read file "+file.getName());
        }

        // Close the input stream and return bytes
        is.close();
        return bytes;
    }

所以基本上现在我发送这些字节数组的Java应用程序有以下code ...

so basically now i am sending those byte array to java application with the following code...

 File source_for_byte=new File(outFilename);//Here is my wave file 

//创建临时的字节数组存储在字节数组文件

//creating temporary byte array to store that files in byte array

 byte[] temp = new byte[(int) source_for_byte.length()];

//然后调用我的方法如上面我说了文件转换的字节数组

//then calling my method as i above stated that converts the file in byte array

temp=getBytesFromFile(source_for_byte);

从这里读音字使用kso​​ap2调用其中的字节数组作为参数,也字符串作为文件路径在服务器上存储与get_wav_byte()方法的Java应用程序的方法。

From here i m using ksoap2 to call java application method in which those array byte as an argument and also string as file path to store at server with the get_wav_byte() method

 String NAMESPACE = "http://test.com";
                String SOAP_ACTION = NAMESPACE + METHOD_NAME;
                // NAMESPACE + method name
                final String URL = "http://192.168.3.106:8080/axis2/services/speechmain?wsdl";

                    METHOD_NAME = "get_wav_byte";
                    try {
                        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
                        request.addProperty("wavbite",temp);

                        request.addProperty("path", "D:\\sound\\latest_recognizer.wav");
                        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                                SoapEnvelope.VER11);
                        envelope.dotNet = true;
                        envelope.setOutputSoapObject(request);
                        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
                        androidHttpTransport.call(SOAP_ACTION, envelope);
                        Object result = envelope.getResponse();
                        ((TextView) findViewById(R.id.gettext1)).setText("NUMBER IS :->   "
                                 + result.toString());

                    } catch (Exception E) {
                        E.printStackTrace();
                        ((TextView) findViewById(R.id.gettext1)).setText("ERROR:"
                                + E.getClass().getName() + ":" + E.getMessage());
                    }

和我的Java应用程序的方法是我从Android的调用是如下...

And my java Application method is that i calling from android is as follows...

 public int get_wav_byte(byte[] wavbite,String path){

        try
            {
                File dstFile = new File(path);
                FileOutputStream out = new FileOutputStream(dstFile);
                    out.write(wavbite, 0, wavbite.length);
                out.close();               
            }
            catch (IOException e)
            {
              System.out.println("IOException : " + e);
            }

         return 0;
         }

和我的问题是,当我运行我的Andr​​oid应用程序调用它给我下面的错误此Web服务

and my Problem is When I run my android application to call this web service its giving me following error

 java.lang.runtimeexception:cannot serialize:[B@40781280]

一件事我想告诉大家,我打电话相同的Java方法从以下code我的.NET应用程序。

One thing More i want to tell that i am calling same Java Method From My .net application with the following code.

static void Main(string[] args)
        {
            byte[] byteArrayFile = File.ReadAllBytes("D:/Projects/ConsoleApplication1/ConsoleApplication1/1347452692320.wav");

            String mypath="D:\\sound\\bhavik_latest_copy_recorded.wav";


            short[] shortwave=ConvertBytesToShorts(byteArrayFile);
          Speech_service.speechmainPortTypeClient obj = new Speech_service.speechmainPortTypeClient();

            obj.get_wav_byte(byteArrayFile,mypath);
}

,只是其工作像冠军和方便地存储我的波形文件

And Simply Its Working like Champ and storing my wave file easily

那么,什么是我的Andr​​oid code,它给了错误的问题。

So what is the Problem in my android Code that it gives the error.

u能告诉我什么回事?

can u please tell me whats going wrong?

感谢您提前。

推荐答案

Ok.I已经解决了我的错误与

Ok.I had Solved my error with the

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);

            new MarshalBase64().register(envelope); // serialization

这篇关于RuntimeException的:不能序列:错误从Android通过发送KSOAP字节数组的Java应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆