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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:03:41+00:00 2026-05-28T03:03:41+00:00

HEre is my RegisterActivity: public class RegisterActivity extends Activity { /** Called when the

  • 0

HEre is my RegisterActivity:

public class RegisterActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.register);
}

public void sendRegistration(View view) {
    TextView txtName = (TextView) findViewById(R.id.txtName);
    TextView txtEmail = (TextView) findViewById(R.id.txtEmail);
    TextView txtPassword = (TextView) findViewById(R.id.txtPassword);
    String strName = txtName.getText().toString();
    String strEmail = txtEmail.getText().toString();
    String strPassword = txtPassword.getText().toString();

    if (strName.isEmpty() || strEmail.isEmpty() || strPassword.isEmpty()) {
        // One or more fields are empty
        Toast toast = Toast
                .makeText(
                        getApplicationContext(),
                        "One or more fields have been left blank. Please fill them in.",
                        Toast.LENGTH_SHORT);
        toast.show();
    } else {

        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://www.******.**/register.php");
        try {
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("name", strName));
            nameValuePairs.add(new BasicNameValuePair("email", strEmail));
            nameValuePairs.add(new BasicNameValuePair("password", strPassword));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

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

            startActivityForResult(new Intent(view.getContext(),
                    RegFinishActivity.class), 0);

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

}

What my goal is, is to validate that the email, name, password is not empty then send a request to my server, but when I run this code on my device, it says “Applciation has crashed”. I am running Android 4.0.3, and infact do have the permission for internet in the manifest. What else could cause this problem? Without the http request, this runs fine, and the next view is shown.

LogCat log from start to finish of application:

01-08 08:58:06.793: D/dalvikvm(20672): GC_CONCURRENT freed 60K, 3% free 9439K/9671K, paused 4ms+6ms
01-08 08:58:06.929: D/OpenGLRenderer(20672): Flushing caches (mode 0)
01-08 08:58:15.597: D/AndroidRuntime(20672): Shutting down VM
01-08 08:58:15.597: W/dalvikvm(20672): threadid=1: thread exiting with uncaught exception (group=0x40a2b1f8)
01-08 08:58:15.609: E/AndroidRuntime(20672): FATAL EXCEPTION: main
01-08 08:58:15.609: E/AndroidRuntime(20672): java.lang.IllegalStateException: Could not execute method of the activity
01-08 08:58:15.609: E/AndroidRuntime(20672):    at android.view.View$1.onClick(View.java:3044)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at android.view.View.performClick(View.java:3511)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at android.view.View$PerformClick.run(View.java:14105)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at android.os.Handler.handleCallback(Handler.java:605)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at android.os.Handler.dispatchMessage(Handler.java:92)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at android.os.Looper.loop(Looper.java:137)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at android.app.ActivityThread.main(ActivityThread.java:4424)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at java.lang.reflect.Method.invokeNative(Native Method)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at java.lang.reflect.Method.invoke(Method.java:511)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at dalvik.system.NativeStart.main(Native Method)
01-08 08:58:15.609: E/AndroidRuntime(20672): Caused by: java.lang.reflect.InvocationTargetException
01-08 08:58:15.609: E/AndroidRuntime(20672):    at java.lang.reflect.Method.invokeNative(Native Method)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at java.lang.reflect.Method.invoke(Method.java:511)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at android.view.View$1.onClick(View.java:3039)
01-08 08:58:15.609: E/AndroidRuntime(20672):    ... 11 more
01-08 08:58:15.609: E/AndroidRuntime(20672): Caused by: android.os.NetworkOnMainThreadException
01-08 08:58:15.609: E/AndroidRuntime(20672):    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at java.net.InetAddress.getAllByName(InetAddress.java:220)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
01-08 08:58:15.609: E/AndroidRuntime(20672):    at sms.web.RegisterActivity.sendRegistration(RegisterActivity.java:58)
01-08 08:58:15.609: E/AndroidRuntime(20672):    ... 14 more
01-08 08:58:18.336: I/Process(20672): Sending signal. PID: 20672 SIG: 9
  • 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-28T03:03:42+00:00Added an answer on May 28, 2026 at 3:03 am

    Have you requested internet permission in your manifest file?

    Add

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

    in your manifest file above the application tag

    Please post your logcat log if you have done this and you still encounter the error.

    As said in my comment, you should use an AsyncTask to perform this task outside of the main Thread. Something like this, but then with correct variable scopes. This class should be added inside you RegisterActivity class as an inner class. YOu can then launch the task by:

    new SendRegisterationTask().execute();
    
    
    
    private class SendRegistrationTask extends AsyncTask<String, String, String> {
    
        protected void onPreExecute() {
            // prepare the request
        }
    
        protected String doInBackground(String... aurl) {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://www.******.**/register.php");
            try {
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                nameValuePairs.add(new BasicNameValuePair("name", strName));
                nameValuePairs.add(new BasicNameValuePair("email", strEmail));
                nameValuePairs.add(new BasicNameValuePair("password", strPassword));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    
                // Execute HTTP Post Request
                HttpResponse response = httpclient.execute(httppost);
    
                startActivityForResult(new Intent(view.getContext(),
                        RegFinishActivity.class), 0);
    
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    
        @Override
        protected void onPostExecute(String result) {
            // Do what you want after the request has been handled
        }
    }
    

    Some of the stuff in the doInBackground could be done in the postExecute or the preExecute like the activity launch.

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

Sidebar

Related Questions

Here's my test function (c#, visual studio 2010): [TestMethod()] public void TestGetRelevantWeeks() { List<sbyte>
Here is an example: I have the generic type called Account. I wish to
Here is my simplified data structure: Object1.h template <class T> class Object1 { private:
Here is my situation: I have a controller action called OrderFromCategory which fills a
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here's a problem I ran into recently. I have attributes strings of the form
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior
Here is a simplification of my database: Table: Property Fields: ID, Address Table: Quote
Here is my code, which takes two version identifiers in the form 1, 5,

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.