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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:56:33+00:00 2026-06-09T20:56:33+00:00

i m new to android development. i am trying to insert data into remote

  • 0

i m new to android development. i am trying to insert data into remote Mysql database through php script using android’s HttpPost. i have added the permission for internet. i am getting forced closed error. My code is below:

   package com.regsiteration.regfi;

    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.List;

    import org.apache.http.HttpResponse;
    import org.apache.http.NameValuePair;
    import org.apache.http.client.ClientProtocolException;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.entity.UrlEncodedFormEntity;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.message.BasicNameValuePair;

    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;

    public class Main extends Activity {


    public void postData() {
        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://xyz.com/folder/register.php");

        try {
            // Add your data
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("email", "demo@ats.in"));
            nameValuePairs.add(new BasicNameValuePair("name", "robin hood"));
            nameValuePairs.add(new BasicNameValuePair("password", "1234590"));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);

        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
        } catch (IOException e) {
            // TODO Auto-generated catch block
        }
    } 

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //postData();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    }

Please tell me what i am missing or doing wrong. Thanks in advance. Here is my logcat trace

08-17 20:16:49.530: I/dalvikvm(630): threadid=3: reacting to signal 3
08-17 20:16:49.654: I/dalvikvm(630): Wrote stack traces to '/data/anr/traces.txt'
08-17 20:16:49.779: D/AndroidRuntime(630): Shutting down VM
08-17 20:16:49.779: W/dalvikvm(630): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
08-17 20:16:49.799: E/AndroidRuntime(630): FATAL EXCEPTION: main
08-17 20:16:49.799: E/AndroidRuntime(630): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.regsiteration.regfi/com.regsiteration.regfi.Main}: android.os.NetworkOnMainThreadException
08-17 20:16:49.799: E/AndroidRuntime(630):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
08-17 20:16:49.799: E/AndroidRuntime(630):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
08-17 20:16:49.799: E/AndroidRuntime(630):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
08-17 20:16:49.799: E/AndroidRuntime(630):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
08-17 20:16:49.799: E/AndroidRuntime(630):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-17 20:16:49.799: E/AndroidRuntime(630):  at android.os.Looper.loop(Looper.java:137)
08-17 20:16:49.799: E/AndroidRuntime(630):  at android.app.ActivityThread.main(ActivityThread.java:4424)
08-17 20:16:49.799: E/AndroidRuntime(630):  at java.lang.reflect.Method.invokeNative(Native Method)
08-17 20:16:49.799: E/AndroidRuntime(630):  at java.lang.reflect.Method.invoke(Method.java:511)
08-17 20:16:49.799: E/AndroidRuntime(630):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-17 20:16:49.799: E/AndroidRuntime(630):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-17 20:16:49.799: E/AndroidRuntime(630):  at dalvik.system.NativeStart.main(Native Method)
08-17 20:16:49.799: E/AndroidRuntime(630): Caused by: android.os.NetworkOnMainThreadException
08-17 20:16:49.799: E/AndroidRuntime(630):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
08-17 20:16:49.799: E/AndroidRuntime(630):  at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
08-17 20:16:49.799: E/AndroidRuntime(630):  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
08-17 20:16:49.799: E/AndroidRuntime(630):  at java.net.InetAddress.getAllByName(InetAddress.java:220)
08-17 20:16:49.799: E/AndroidRuntime(630):  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
08-17 20:16:49.799: E/AndroidRuntime(630):  at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
08-17 20:16:49.799: E/AndroidRuntime(630):  at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
08-17 20:16:49.799: E/AndroidRuntime(630):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
08-17 20:16:49.799: E/AndroidRuntime(630):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
08-17 20:16:49.799: E/AndroidRuntime(630):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
08-17 20:16:49.799: E/AndroidRuntime(630):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
08-17 20:16:49.799: E/AndroidRuntime(630):  at com.regsiteration.regfi.Main.postData(Main.java:37)
08-17 20:16:49.799: E/AndroidRuntime(630):  at com.regsiteration.regfi.Main.onCreate(Main.java:50)
08-17 20:16:49.799: E/AndroidRuntime(630):  at android.app.Activity.performCreate(Activity.java:4465)
08-17 20:16:49.799: E/AndroidRuntime(630):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-17 20:16:49.799: E/AndroidRuntime(630):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
08-17 20:16:49.799: E/AndroidRuntime(630):  ... 11 more
08-17 20:16:49.960: I/dalvikvm(630): threadid=3: reacting to signal 3
08-17 20:16:49.970: I/dalvikvm(630): Wrote stack traces to '/data/anr/traces.txt'
08-17 20:16:50.340: I/dalvikvm(630): threadid=3: reacting to signal 3
08-17 20:16:50.350: I/dalvikvm(630): Wrote stack traces to '/data/anr/traces.txt'
  • 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-09T20:56:35+00:00Added an answer on June 9, 2026 at 8:56 pm
    Caused by: android.os.NetworkOnMainThreadException
    

    This is your error. Network stuff can’t be done on the UI thread in newer SDK versions.
    You can “override” this with

      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
      StrictMode.setThreadPolicy(policy);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to using SQLite databases and android mobile development. I am trying
I am new to android development and I've hit a hurdle when trying to
I am new to android development . I'm trying to download and run the
I'm new to Android development, i'm trying to port an IOS app to Android.
I'm new to Android development. My OS is WinXP. I'm trying to install two
hey, im new to android development and trying to make my first application. What
I'm new in android development and I am trying out the WebView example in
I am very new to android development and have been trying to draw a
I'm new to Android development. I'm trying to get a simple HelloWorld app going
I am new to Android development and running into a bizarre issue for which

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.