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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:40:32+00:00 2026-06-07T18:40:32+00:00

I am having a problem doing a simple http post request from my android

  • 0

I am having a problem doing a simple http post request from my android app to my Google Application.

So here is the error message:

07-16 15:58:02.314: E/AndroidRuntime(911): FATAL EXCEPTION: main
07-16 15:58:02.314: E/AndroidRuntime(911): java.lang.IllegalStateException: Could not     execute method of the activity

It happens in my android app at the httpclient.execute command:

ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://localhost:8888/mywebapp");
try {
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
}

On my server there is no trace that I arrive in my post method:

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws  ServletException, IOException {
System.out.println("SYL: POST request received");
super.doPost(req, resp);
}

The server is google webb app running under my eclipse locally with this conf:

<servlet-name>MyWebApp</servlet-name>
<servlet-class>com.my.mywebapp.MyWebAppServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyWebApp</servlet-name>
<url-pattern>/mywebapp/*</url-pattern>
</servlet-mapping>

If a test a get method that I call through a web navigator it works.
But calling the get in java (same way as I do for the post) does not work.
It like in the android app the connection can not be make with my server.

I put these permissions:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Can someone help me please??

Thank you.

PS:

Still the same error with replaceing localhost with 10.0.2.2.
I am copying the complete trace:

07-16 18:13:34.945: E/AndroidRuntime(1081): FATAL EXCEPTION: main
07-16 18:13:34.945: E/AndroidRuntime(1081): java.lang.IllegalStateException: Could not execute method of the activity
07-16 18:13:34.945: E/AndroidRuntime(1081):     at android.view.View$1.onClick(View.java:3044)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at android.view.View.performClick(View.java:3511)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at android.view.View$PerformClick.run(View.java:14105)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at android.os.Handler.handleCallback(Handler.java:605)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at android.os.Handler.dispatchMessage(Handler.java:92)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at android.os.Looper.loop(Looper.java:137)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at android.app.ActivityThread.main(ActivityThread.java:4424)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at java.lang.reflect.Method.invokeNative(Native Method)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at java.lang.reflect.Method.invoke(Method.java:511)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at dalvik.system.NativeStart.main(Native Method)
07-16 18:13:34.945: E/AndroidRuntime(1081): Caused by: java.lang.reflect.InvocationTargetException
07-16 18:13:34.945: E/AndroidRuntime(1081):     at java.lang.reflect.Method.invokeNative(Native Method)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at java.lang.reflect.Method.invoke(Method.java:511)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at android.view.View$1.onClick(View.java:3039)
07-16 18:13:34.945: E/AndroidRuntime(1081):     ... 11 more
07-16 18:13:34.945: E/AndroidRuntime(1081): Caused by: android.os.NetworkOnMainThreadException
07-16 18:13:34.945: E/AndroidRuntime(1081):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at java.net.InetAddress.getAllByName(InetAddress.java:220)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
07-16 18:13:34.945: E/AndroidRuntime(1081):     at com.my.my.MyActivity.sendMessage(MyActivity.java:72)
07-16 18:13:34.945: E/AndroidRuntime(1081):     ... 14 more
  • 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-07T18:40:34+00:00Added an answer on June 7, 2026 at 6:40 pm

    If you are debugging in a local server, change the IP you want to access, and set this one: 10.0.2.2.
    So, your httpost will look this way:

    HttpPost httppost = new HttpPost("http://10.0.2.2:8888/mywebapp");
    

    For more info, 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 having a problem with my Android app. It's probably a simple Java problem,
This is a seemingly simple problem but I am having trouble doing it in
I am having trouble doing a simple download of an XML file from a
I'm new from python and I'm having some issue in doing a simple thing.
Hello I am a new user to Python and I am having problem doing
I'm having a problem with doing a sendSynchronousRequest failing. It only fails after I
I'm having a problem setting a cookie and doing a 302 redirect In chrome
Im doing a page in .asp and im having this problem ... I have
Having problem with the middle Div not expanding to the width http://acs.graphicsmayhem.com/images/middiv.jpg Ok, how
i'm having problem to deal with charset in ruby on rails app, specificially in

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.