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

  • SEARCH
  • Home
  • 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 8945803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:20:28+00:00 2026-06-15T12:20:28+00:00

i am trying to post data on wamp’s apache localhost using port no 8080

  • 0

i am trying to post data on wamp’s apache localhost using port no 8080 using below given code.

public class postdata extends Activity
{
    Button btnpost;
    EditText txtname,txtsalary;
    TextView lblstatus;
    String hostname;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.main3);
        btnpost=(Button)this.findViewById(R.id.btnpost);
        txtname=(EditText)this.findViewById(R.id.txtname);
        txtsalary=(EditText)this.findViewById(R.id.txtsalary);
        final HttpClient client = new DefaultHttpClient();
        final HttpPost post = new HttpPost("http://127.0.0.1:8080/andy1/script2.php");
        btnpost.setOnClickListener(new View.OnClickListener()
        {

            @Override
            public void onClick(View arg0)
            {
                try
                {
                    List<NameValuePair> pair = new ArrayList<NameValuePair>(2);
                    pair.add(new BasicNameValuePair("txtname",txtname.getText().toString()));
                    pair.add(new BasicNameValuePair("txtsalary",txtsalary.getText().toString()));
                    post.setEntity(new UrlEncodedFormEntity(pair));
                    HttpResponse response = client.execute(post);
                    Toast.makeText(getApplicationContext(), "Record Saved",1000).show();
                }
                 catch (ClientProtocolException e)
                    {
                        // TODO Auto-generated catch block
                    }
                    catch (IOException e)
                    {
                        Toast.makeText(getApplicationContext(), "Error in uploading",1000).show();
                    }
            }
        });
    }

}

whenever i run above code on emulator i got the following error.

12-03 10:10:51.237: E/AndroidRuntime(281): FATAL EXCEPTION: main
12-03 10:10:51.237: E/AndroidRuntime(281): java.lang.IllegalArgumentException: Host name may not be null
12-03 10:10:51.237: E/AndroidRuntime(281):  at org.apache.http.HttpHost.<init>(HttpHost.java:83)
12-03 10:10:51.237: E/AndroidRuntime(281):  at org.apache.http.impl.client.AbstractHttpClient.determineTarget(AbstractHttpClient.java:497)
12-03 10:10:51.237: E/AndroidRuntime(281):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
12-03 10:10:51.237: E/AndroidRuntime(281):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
12-03 10:10:51.237: E/AndroidRuntime(281):  at demo.network.postdata$1.onClick(postdata.java:65)
12-03 10:10:51.237: E/AndroidRuntime(281):  at android.view.View.performClick(View.java:2408)
12-03 10:10:51.237: E/AndroidRuntime(281):  at android.view.View$PerformClick.run(View.java:8816)
12-03 10:10:51.237: E/AndroidRuntime(281):  at android.os.Handler.handleCallback(Handler.java:587)
12-03 10:10:51.237: E/AndroidRuntime(281):  at android.os.Handler.dispatchMessage(Handler.java:92)
12-03 10:10:51.237: E/AndroidRuntime(281):  at android.os.Looper.loop(Looper.java:123)
12-03 10:10:51.237: E/AndroidRuntime(281):  at android.app.ActivityThread.main(ActivityThread.java:4627)
12-03 10:10:51.237: E/AndroidRuntime(281):  at java.lang.reflect.Method.invokeNative(Native Method)
12-03 10:10:51.237: E/AndroidRuntime(281):  at java.lang.reflect.Method.invoke(Method.java:521)
12-03 10:10:51.237: E/AndroidRuntime(281):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-03 10:10:51.237: E/AndroidRuntime(281):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-03 10:10:51.237: E/AndroidRuntime(281):  at dalvik.system.NativeStart.main(Native Method)  

i have also tried to use 10.0.0.2 as IP address as it was one of the solution posted in other post but did not work at all.
i have tried lot to solve this error using net but could not succeed.

  • 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-15T12:20:30+00:00Added an answer on June 15, 2026 at 12:20 pm

    Unless you are running a Web server in the emulator you need to use the IP address of your development machine. Use ifconfig (Linux, etc.) or ipconfig (Windows) to find out what the address is. Should be something like ‘192.168.xxx.xxx` for a local network.

    Or use 10.0.2.2 to refer to the development machine’s loopback interface as suggested in the other answer. Here’s the link to the relevant docs for the emulator: http://developer.android.com/tools/devices/emulator.html#networkaddresses

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

Sidebar

Related Questions

I'm trying to post data on a server using java HttpUrlConnection class. It seems
Trying to post JSON data to Spring controller.. Not working at all JSP Code:
I am trying to post data to bing with this code function PostExample: string;
I'm trying to POST some multipart form data to my server using a Browser
I'm trying to POST data to an external url using HttpWebRequest, then i need
Im having trouble trying to post data correctly using jQuery/AJAX I have the following...
I'm trying to post 2 fields, id and data, to a servlet using HttpClient.
I'm trying to POST some data as if I was using FORM on HTML
I am trying to post data to my server (vb.net) using mobile devices. I've
i am trying to post data via HTTP Post using name value key pair.

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.