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

The Archive Base Latest Questions

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

I’m getting a force close when I perform this. The thing is. The data

  • 0

I’m getting a force close when I perform this. The thing is. The data does get send to my database. So it is in my database but I read my logcat and it says that I got a problem in my DinBackground here is my code:

// JSON Response node names
private static String KEY_SUCCESS = "success";
private static String KEY_ERROR = "error";
private static String KEY_ERROR_MSG = "error_msg";
private static String KEY_UID = "uid";
private static String KEY_NAME = "name";
private static String KEY_EMAIL = "email";
private static String KEY_CREATED_AT = "created_at";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.register);


    // Importing all assets like buttons, text fields
    inputFullName = (EditText) findViewById(R.id.registerName);
    inputEmail = (EditText) findViewById(R.id.registerEmail);
    inputPassword = (EditText) findViewById(R.id.registerPassword);
    btnRegister = (Button) findViewById(R.id.btnRegister);
    btnLinkToLogin = (Button) findViewById(R.id.btnLinkToLoginScreen);
    registerErrorMsg = (TextView) findViewById(R.id.register_error);

    // Register Button Click event
    btnRegister.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {

            new CreateNewProduct().execute();
        }
    });


}

class CreateNewProduct extends AsyncTask<String, String, String> {

    /**
     * Before starting background thread Show Progress Dialog
     * */
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(RegisterActivity.this);
        pDialog.setMessage("Loading");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();

    }

    /**
     * Creating product
     * */
    protected String doInBackground(String... args) {
        String name = inputFullName.getText().toString();
        String email = inputEmail.getText().toString();
        String password = inputPassword.getText().toString();
        UserFunctions userFunction = new UserFunctions();
        JSONObject json = userFunction.registerUser(name, email, password);

        // check for login response
        try {
            if (json.getString(KEY_SUCCESS) != null) {
                registerErrorMsg.setText("");
                String res = json.getString(KEY_SUCCESS);
                if(Integer.parseInt(res) == 1){
                    // user successfully registred
                    // Store user details in SQLite Database
                    DatabaseHandler db = new DatabaseHandler(getApplicationContext());
                    JSONObject json_user = json.getJSONObject("user");

                    // Clear all previous data in database
                    userFunction.logoutUser(getApplicationContext());
                    db.addUser(json_user.getString(KEY_NAME), json_user.getString(KEY_EMAIL), json.getString(KEY_UID), json_user.getString(KEY_CREATED_AT));
                    // Launch Dashboard Screen

                    // Close Registration Screen
                    finish();
                }else{
                    // Error in registration
                    registerErrorMsg.setText("Error occured in registration");
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }

    /**
     * After completing background task Dismiss the progress dialog
     * **/
    protected void onPostExecute(String file_url) {
        // dismiss the dialog once done
        pDialog.dismiss();
        Intent dashboard = new Intent(getApplicationContext(), DashboardActivity.class);
        // Close all views before launching Dashboard
        dashboard.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(dashboard);
    }

}

Here is my logcat:

12-02 15:35:33.761: E/AndroidRuntime(671): FATAL EXCEPTION: AsyncTask #1
12-02 15:35:33.761: E/AndroidRuntime(671): java.lang.RuntimeException: An error occured while executing doInBackground()
12-02 15:35:33.761: E/AndroidRuntime(671):  at android.os.AsyncTask$3.done(AsyncTask.java:278)
12-02 15:35:33.761: E/AndroidRuntime(671):  at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
12-02 15:35:33.761: E/AndroidRuntime(671):  at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
12-02 15:35:33.761: E/AndroidRuntime(671):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
12-02 15:35:33.761: E/AndroidRuntime(671):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
12-02 15:35:33.761: E/AndroidRuntime(671):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
12-02 15:35:33.761: E/AndroidRuntime(671):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
12-02 15:35:33.761: E/AndroidRuntime(671):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
12-02 15:35:33.761: E/AndroidRuntime(671):  at java.lang.Thread.run(Thread.java:856)
12-02 15:35:33.761: E/AndroidRuntime(671): Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
12-02 15:35:33.761: E/AndroidRuntime(671):  at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4039)
12-02 15:35:33.761: E/AndroidRuntime(671):  at android.view.ViewRootImpl.invalidateChild(ViewRootImpl.java:722)
12-02 15:35:33.761: E/AndroidRuntime(671):  at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:771)
12-02 15:35:33.761: E/AndroidRuntime(671):  at android.view.ViewGroup.invalidateChild(ViewGroup.java:4005)
12-02 15:35:33.761: E/AndroidRuntime(671):  at android.view.View.invalidate(View.java:8576)
12-02 15:35:33.761: E/AndroidRuntime(671):  at android.view.View.invalidate(View.java:8527)
12-02 15:35:33.761: E/AndroidRuntime(671):  at android.widget.TextView.checkForRelayout(TextView.java:6760)
12-02 15:35:33.761: E/AndroidRuntime(671):  at android.widget.TextView.setText(TextView.java:3306)
12-02 15:35:33.761: E/AndroidRuntime(671):  at android.widget.TextView.setText(TextView.java:3162)
12-02 15:35:33.761: E/AndroidRuntime(671):  at android.widget.TextView.setText(TextView.java:3137)
12-02 15:35:33.761: E/AndroidRuntime(671):  at com.laurenswuyts.find.it.RegisterActivity$CreateNewProduct.doInBackground(RegisterActivity.java:100)
12-02 15:35:33.761: E/AndroidRuntime(671):  at com.laurenswuyts.find.it.RegisterActivity$CreateNewProduct.doInBackground(RegisterActivity.java:1)
12-02 15:35:33.761: E/AndroidRuntime(671):  at android.os.AsyncTask$2.call(AsyncTask.java:264)
12-02 15:35:33.761: E/AndroidRuntime(671):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
12-02 15:35:33.761: E/AndroidRuntime(671):  ... 5 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-15T16:55:29+00:00Added an answer on June 15, 2026 at 4:55 pm

    You are accessing UI elements inside doInBackground(). doInBackgroud(), as the name suggests, is a background (non-UI) thread and does not have access to the UI elements. So, you should put that code inside onPreExecute() which is a UI thread. Get the user input from the UI elements in onPreExecute and store them in Strings and use them later in your doInBackground().

    class CreateNewProduct extends AsyncTask<String, String, String> {
    
        /**
         * Before starting background thread Show Progress Dialog
         * */
        String name, email, password;
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(RegisterActivity.this);
            pDialog.setMessage("Loading");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
            name = inputFullName.getText().toString();
            email = inputEmail.getText().toString();
            password = inputPassword.getText().toString();
    
        }
    
        /**
         * Creating product
         * */
        protected String doInBackground(String... args) {
    
            UserFunctions userFunction = new UserFunctions();
            JSONObject json = userFunction.registerUser(name, email, password);
    
            // check for login response
            try {
                if (json.getString(KEY_SUCCESS) != null) {
                    registerErrorMsg.setText("");
                    String res = json.getString(KEY_SUCCESS);
                    if(Integer.parseInt(res) == 1){
                        // user successfully registred
                        // Store user details in SQLite Database
                        DatabaseHandler db = new DatabaseHandler(getApplicationContext());
                        JSONObject json_user = json.getJSONObject("user");
    
                        // Clear all previous data in database
                        userFunction.logoutUser(getApplicationContext());
                        db.addUser(json_user.getString(KEY_NAME), json_user.getString(KEY_EMAIL), json.getString(KEY_UID), json_user.getString(KEY_CREATED_AT));
                        // Launch Dashboard Screen
    
                        // Close Registration Screen
                        finish();
                    }else{
                        // Error in registration
                        //show error message to user in onPostExecute
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
    
            return null;
        }
    
        /**
         * After completing background task Dismiss the progress dialog
         * **/
        protected void onPostExecute(String file_url) {
            // dismiss the dialog once done
            pDialog.dismiss();
            Intent dashboard = new Intent(getApplicationContext(), DashboardActivity.class);
            // Close all views before launching Dashboard
            dashboard.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(dashboard);
        }
    
    }
    

    Additionally,
    your parameters are wrong when you are calling the AsyncTask.

    Since you have declared it as class CreateNewProduct extends AsyncTask<String, String, String> , you need to pass a String when you are making a call to the AsyncTask.

    So, new CreateNewProduct().execute(""); would be the correct way to make a call to it.

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

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
I want to construct a data frame in an Rcpp function, but when I
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.