0

i'm trying to post on the servers database didn't know where is the error exactly but it seems to be in the Asynctask check out the logcat

so I'm really not sure if the error comes from the PHP files or the Java code

 07-07 20:07:30.533: E/WindowManager(1688): Activity com.example.ahliaevents.AddCard has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@421da710 that was originally added here
07-07 20:07:30.533: E/WindowManager(1688): android.view.WindowLeaked: Activity com.example.ahliaevents.AddCard has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@421da710 that was originally added here
07-07 20:07:30.533: E/WindowManager(1688):  at android.view.ViewRootImpl.<init>(ViewRootImpl.java:374)
07-07 20:07:30.533: E/WindowManager(1688):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
07-07 20:07:30.533: E/WindowManager(1688):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
07-07 20:07:30.533: E/WindowManager(1688):  at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
07-07 20:07:30.533: E/WindowManager(1688):  at android.view.Window$LocalWindowManager.addView(Window.java:547)
07-07 20:07:30.533: E/WindowManager(1688):  at android.app.Dialog.show(Dialog.java:277)
07-07 20:07:30.533: E/WindowManager(1688):  at com.example.ahliaevents.AddCard$CreateNewCard.onPreExecute(AddCard.java:75)
07-07 20:07:30.533: E/WindowManager(1688):  at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
07-07 20:07:30.533: E/WindowManager(1688):  at android.os.AsyncTask.execute(AsyncTask.java:534)
07-07 20:07:30.533: E/WindowManager(1688):  at com.example.ahliaevents.AddCard$1.onClick(AddCard.java:55)
07-07 20:07:30.533: E/WindowManager(1688):  at android.view.View.performClick(View.java:4084)
07-07 20:07:30.533: E/WindowManager(1688):  at android.view.View$PerformClick.run(View.java:16966)
07-07 20:07:30.533: E/WindowManager(1688):  at android.os.Handler.handleCallback(Handler.java:615)
07-07 20:07:30.533: E/WindowManager(1688):  at android.os.Handler.dispatchMessage(Handler.java:92)
07-07 20:07:30.533: E/WindowManager(1688):  at android.os.Looper.loop(Looper.java:137)
07-07 20:07:30.533: E/WindowManager(1688):  at android.app.ActivityThread.main(ActivityThread.java:4745)
07-07 20:07:30.533: E/WindowManager(1688):  at java.lang.reflect.Method.invokeNative(Native Method)
07-07 20:07:30.533: E/WindowManager(1688):  at java.lang.reflect.Method.invoke(Method.java:511)
07-07 20:07:30.533: E/WindowManager(1688):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-07 20:07:30.533: E/WindowManager(1688):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-07 20:07:30.533: E/WindowManager(1688):  at dalvik.system.NativeStart.main(Native Method)

this is my class

public class AddCard extends Activity {

    // Progress Dialog
    private ProgressDialog pDialog;

    JSONParser jsonParser = new JSONParser();
    EditText inputName,inputPhone,inputPosition,inputCollege;

    // url to create new product
    private static String url_create_card = "#####://####/####/#####.php";

    // JSON Node names
    private static final String TAG_SUCCESS = "success";

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

        // Edit Text
        inputName = (EditText) findViewById(R.id.addstudentname);
        inputCollege = (EditText) findViewById(R.id.addstudentcollege);
        inputPosition = (EditText) findViewById(R.id.addstudentposition);
        inputPhone = (EditText) findViewById(R.id.addstudentphone);

        // Create button
        Button btnCreateProduct = (Button) findViewById(R.id.addcardsave);

        // button click event
        btnCreateProduct.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                // creating new product in background thread
                new CreateNewCard().execute();
            }
        });
    }

    /**
     * Background Async Task to Create new product
     * */
    class CreateNewCard extends AsyncTask<String, String, String> {

        /**
         * Before starting background thread Show Progress Dialo
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(AddCard.this);
            pDialog.setMessage("Creating Student Card..");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }

        /**
         * Creating product
         * */
        protected String doInBackground(String... args) {
            String name = inputName.getText().toString();
            String position = inputPosition.getText().toString();
            String college = inputCollege.getText().toString();
            String phone = inputPhone.getText().toString();

            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("name", name));
            params.add(new BasicNameValuePair("position", position));
            params.add(new BasicNameValuePair("college", college));
            params.add(new BasicNameValuePair("phone", phone));

            // getting JSON Object
            // Note that create product url accepts POST method
            JSONObject json = jsonParser.makeHttpRequest(url_create_card,
                    "POST", params);

            // check log cat fro response
            Log.d("Create Response", json.toString());

            // check for success tag
            try {
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {
                    // successfully created product
                    Intent i = new Intent(getApplicationContext(), MainActivity.class);
                    startActivity(i);

                    // closing this screen
                    finish();
                } else {
                    // failed to create product
                }
            } 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();
        }

    }
}

1 Answers1

0

No it is not the server side error. Read https://stackoverflow.com/a/9492974/2069130 and understand error. Actually, you can't do some kind of UI actions in doInBackGround. You have to either put that piece of code in onPostExecute or you have to use

Activity_Name.this.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                // your stuff to update the UI

            }
        });

around that code

Community
  • 1
  • 1
Husnain Iqbal
  • 466
  • 6
  • 16