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 6709521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:53:31+00:00 2026-05-26T07:53:31+00:00

I am new to android. So, not able to trace out the error message

  • 0
 I am new to android. So, not able to trace out the error message while uploading image to the server. 

I got some code from the internet for uploading image to the server and the link is and changed my program accordingly . When am trying to run the program it is giving error message in the emulator as following screen shot.enter image description here

And even checked all the things in the local host and it is running fine. And here is my code for upload image.Please check this and give me some suggestions.

public class uploadimage extends Activity {

    InputStream inputStream;

        @Override

    public void onCreate(Bundle icicle) {

            super.onCreate(icicle);

            setContentView(R.layout.main);



            Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.icon);           ByteArrayOutputStream stream = new ByteArrayOutputStream();

            bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream); //compress to which format you want.

            byte [] byte_arr = stream.toByteArray();

            String image_str = Base64.encodeBytes(byte_arr);

            ArrayList<NameValuePair> nameValuePairs = new  ArrayList<NameValuePair>();



            nameValuePairs.add(new BasicNameValuePair("image",image_str));



            try{

                HttpClient httpclient = new DefaultHttpClient();

                HttpPost httppost = new HttpPost("http://localhost/Upload_image_ANDROID/upload_image.php");

                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                HttpResponse response = httpclient.execute(httppost);

                String the_string_response = convertResponseToString(response);

                Toast.makeText(uploadimage.this, "Response " + the_string_response, Toast.LENGTH_LONG).show();

            }catch(Exception e){

                  Toast.makeText(uploadimage.this, "ERROR " + e.getMessage(), Toast.LENGTH_LONG).show();

                  System.out.println("Error in http connection "+e.toString());

            }

        }


        public String convertResponseToString(HttpResponse response) throws IllegalStateException, IOException{



             String res = "";

             StringBuffer buffer = new StringBuffer();

             inputStream = response.getEntity().getContent();

             int contentLength = (int) response.getEntity().getContentLength(); //getting content length…..

             Toast.makeText(uploadimage.this, "contentLength : " + contentLength, Toast.LENGTH_LONG).show();

             if (contentLength < 0){

             }

             else{

                    byte[] data = new byte[512];

                    int len = 0;

                    try
                    {

                        while (-1 != (len = inputStream.read(data)) )

                        {

                            buffer.append(new String(data, 0, len)); //converting to string and appending  to stringbuffer…..

                        }

                    }

                    catch (IOException e)

                    {

                        e.printStackTrace();

                    }

                    try

                    {

                        inputStream.close(); // closing the stream…..

                    }

                    catch (IOException e)

                    {

                        e.printStackTrace();

                    }

                    res = buffer.toString();     // converting stringbuffer to string…..



                    Toast.makeText(uploadimage.this, "Result : " + res, Toast.LENGTH_LONG).show();

                    //System.out.println("Response => " +  EntityUtils.toString(response.getEntity()));

             }

             return res;

        }

}

Thanks 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-05-26T07:53:32+00:00Added an answer on May 26, 2026 at 7:53 am

    Instead of

    "http://localhost"
    

    use

    http://10.0.2.2

    its for emulator. And if you want to test for device then use specific IP of System given by router or network.

    Thankx.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to android trying to work on uploading image in to server.
I am still pretty new to Android development, and I have not been able
Iam new to android. I got a example for accessing google maps from some
Extreme Android developer newbie here...well, new to Android development, not development in general. I
I'm new to Java/Eclipse/Android, so this is probably an easy (if not stupid) question:
I'm pretty new to Android dev and still working out a lot of things.
I can't figure out why I'm not able to play the video in my
Hi i have a problem i'm not able to solve. In my Android\java application
code is given below, problem is i am not able to remove Main tab
I am very new to Android and I am having problems figuring out how

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.