0

I'm really struggling in this error, I tried a lot of things, but I think I dont have enought knowledge to fix this... Could you please help me??

This is my class

public class Profile_Page extends Activity {

TextView profile_user;
TextView profile_nombre;
TextView profile_email;
TextView profile_fuentes;
String id, email;


// Progress Dialog
private ProgressDialog pDialog;

// JSON Parser Class
JSONParser jsonParser = new JSONParser();

// URL De Información del Usuario
private static final String url_user_details = "http://example.com/usserdetails.php";


// JSON Node Names
private static final String TAG_SUCCESS = "success";
private static final String TAG_USER = "user";
private static final String TAG_ID = "id";
private static final String TAG_USERNAME = "usuario";
private static final String TAG_NAME = "nombre";
private static final String TAG_EMAIL = "email";
private static final String TAG_FOUNTAINS = "fuentes_visitadas";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_profile__page);
    profile_user = findViewById(R.id.profile_user);
    profile_nombre = findViewById(R.id.profile_name);
    profile_email = findViewById(R.id.profile_email);
    profile_fuentes = findViewById(R.id.profile_fuentes);

    id = "1";

    new GetUserDetails().execute();


}

In the same class i have the Backgroundtask method that get info from a PHP web service, i get the correct data from the database but whe i try to put it in a variable to change my textview with the info i get an error.

/**
 * Background Async Task to Get complete product details
 * */
class GetUserDetails extends AsyncTask<String, Void, String> {


    @Override
    protected void onPreExecute() {

    }

    protected String doInBackground(String... parans) {

                // Check for success tag
                int success;
                try {
                    // Building Parameters
                    List<NameValuePair> params = new ArrayList<NameValuePair>();
                    params.add(new BasicNameValuePair("id", id));

                    // getting product details by making HTTP request
                    // Note that product details url will use GET request
                    JSONObject json = jsonParser.makeHttpRequest(
                            url_user_details, "GET", params);

                    // check your log for json response
                    Log.d("Single Product Details", json.toString());

                    // json success tag
                    success = json.getInt(TAG_SUCCESS);
                    if (success == 1) {
                        // successfully received product details
                        JSONArray productObj = json
                                .getJSONArray(TAG_USER); // JSON Array

                        // get first product object from JSON Array
                        JSONObject product = productObj.getJSONObject(0);

                        // display product data in TextViews
                        profile_user.setText(product.getString(TAG_USERNAME));
                        profile_nombre.setText(product.getString(TAG_NAME));
                        profile_email.setText(product.getString(TAG_EMAIL));
                        profile_fuentes.setText(product.getString(TAG_FOUNTAINS));

                    }else{
                        // product with pid not found
                    }
                } 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 got all details
        //pDialog.dismiss();
    }


}

So when I run the app as I told you I can get the data but I get an error and the app stop working.

Here's the error. Error

Thanks By the way, i tried searching people with the same error but i couldnt fix it.

  • 2
    Possible duplicate of [Android "Only the original thread that created a view hierarchy can touch its views."](https://stackoverflow.com/questions/5161951/android-only-the-original-thread-that-created-a-view-hierarchy-can-touch-its-vi) – ADM May 02 '18 at 16:32
  • Did you manage to make this work?@GonzaloPaniagua – Levi Moreira Jun 01 '18 at 11:13
  • Yes I did, I just leave the WebService and tried SQLite, so hard and too many problems with the WebService. Btw Thanks for the help. @LeviAlbuquerque –  Jun 04 '18 at 06:43

0 Answers0