Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8527925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:41:17+00:00 2026-06-11T08:41:17+00:00

I have to Send Byte Array to my java application From Android device.I m

  • 0

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.

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().

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;
    }

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);

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());
                    }

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;
         }

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]

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

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

can u please tell me whats going wrong?

thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:41:18+00:00Added an answer on June 11, 2026 at 8:41 am

    Ok.I had Solved my error with the

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                        SoapEnvelope.VER11);
    
                new MarshalBase64().register(envelope); // serialization
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .NET web service that takes a byte array. I have a
I am using Lotus Notes Java API for my application. I have send one
I have to send the audio data in byte array obtain by recording from
I have to send a byte array (encoded photo) from my PHP client to
I am using UTF-8 encoding to try and send a byte array from my
I have a WCF service operation that accepts a byte array as part of
I am trying to send an image from a Java desktop application to a
I'm using Java sockets for client - server application. I have a situation when
I have WCF service that is IIS-hosted and I have to send binary data
I'm developing an Android App that should send an image to my ASP.NET Web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.