0

我有一个使用 JSON 或 mysql 作为数据库的 android 应用程序。在这种情况下,用户必须输入某个数字,如果输入错误,它会调用自己的活动并说输入的数字错误。我尝试了五次或更多次或有时,我输入错误的数字,它会被强制关闭。我不明白为什么会发生。这是我的示例代码

Intent start = getIntent();
    try{
        int cekStart = start.getExtras().getInt("status");
        Toast.makeText(getBaseContext(), "Maaf Tidak Terdaftar", 3).show();
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setCancelable(false);
        //AlertDialog.Builder alert = new AlertDialog.Builder(this); 
        alert.setTitle("Login"); 
        alert.setMessage("Masukkan Data Anda"); 

        // Set an EditText view to get user input 
        LinearLayout lay=new LinearLayout(this); 
        lay.setOrientation(LinearLayout.VERTICAL); 
        final EditText no_pas = new EditText(this); 
        no_pas.setHint("Nomor Pasien"); 
        lay.addView(no_pas); 
        alert.setView(lay); 
        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
            public void onClick(DialogInterface dialog, int whichButton) {
                if(no_pasien==null)
                no_pasien = no_pas.getText().toString();
                new LoginProses().execute();

            } 
        }); 
        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
            public void onClick(DialogInterface dialog, int whichButton) { 
                finish();
            } 
        }); 
        alert.show();
    }catch (Exception e) {
        // TODO: handle exception
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setCancelable(false);
        //AlertDialog.Builder alert = new AlertDialog.Builder(this); 
        alert.setTitle("Login"); 
        alert.setMessage("Masukkan Data Anda"); 

        // Set an EditText view to get user input 
        LinearLayout lay=new LinearLayout(this); 
        lay.setOrientation(LinearLayout.VERTICAL); 
        final EditText no_pas = new EditText(this); 
        no_pas.setHint("Nomor Pasien"); 
        lay.addView(no_pas); 
        alert.setView(lay); 
        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
            public void onClick(DialogInterface dialog, int whichButton) { 
                no_pasien = no_pas.getText().toString();
                new LoginProses().execute();

            } 
        }); 
        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
            public void onClick(DialogInterface dialog, int whichButton) { 
                finish();
            } 
        }); 
        alert.show();
    }


}

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

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

    /**
     * Creating product
     * */
    protected String doInBackground(String... args) {
        String no = no_pasien;

        // Building Parameters
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("no_pasien", no));

        // getting JSON Object
        // Note that create product url accepts POST method

        JSONObject json = jsonParser.makeHttpRequest(url_login,
                "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 goMainAct = new Intent();
                goMainAct.setClass(Login.this, MainActivity.class);
                finish();
                startActivity(goMainAct);
            } else {
                // failed to create product
                Intent getReload = getIntent();
                getReload.putExtra("status", 1);
                finish();
                startActivity(getReload);
            }

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

        return null;
    }
    protected void onPostExecute(String file_url) {
        // dismiss the dialog once done
        pDialog.dismiss();
    }
}

----UPDATE ERROR LOG-----这是错误日志..

06-24 05:28:36.257: E/WindowManager(12036): Activity com.iteadstudio.Login has leaked     window com.android.internal.policy.impl.PhoneWindow$DecorView@4179ce28 that was originally added here
06-24 05:28:36.257: E/WindowManager(12036): android.view.WindowLeaked: Activity com.iteadstudio.Login has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4179ce28 that was originally added here
06-24 05:28:36.257: E/WindowManager(12036):     at android.view.ViewRootImpl.<init>(ViewRootImpl.java:344)
06-24 05:28:36.257: E/WindowManager(12036):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:267)
06-24 05:28:36.257: E/WindowManager(12036):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
06-24 05:28:36.257: E/WindowManager(12036):     at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
06-24 05:28:36.257: E/WindowManager(12036):     at android.view.Window$LocalWindowManager.addView(Window.java:537)
06-24 05:28:36.257: E/WindowManager(12036):     at android.app.Dialog.show(Dialog.java:278)
06-24 05:28:36.257: E/WindowManager(12036):     at com.iteadstudio.Login$LoginProses.onPreExecute(Login.java:122)
06-24 05:28:36.257: E/WindowManager(12036):     at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:561)
06-24 05:28:36.257: E/WindowManager(12036):     at android.os.AsyncTask.execute(AsyncTask.java:511)
06-24 05:28:36.257: E/WindowManager(12036):     at com.iteadstudio.Login$1.onClick(Login.java:67)
06-24 05:28:36.257: E/WindowManager(12036):     at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
06-24 05:28:36.257: E/WindowManager(12036):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-24 05:28:36.257: E/WindowManager(12036):     at android.os.Looper.loop(Looper.java:137)
06-24 05:28:36.257: E/WindowManager(12036):     at android.app.ActivityThread.main(ActivityThread.java:4441)
06-24 05:28:36.257: E/WindowManager(12036):     at java.lang.reflect.Method.invokeNative(Native Method)
06-24 05:28:36.257: E/WindowManager(12036):     at java.lang.reflect.Method.invoke(Method.java:511)
06-24 05:28:36.257: E/WindowManager(12036):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
06-24 05:28:36.257: E/WindowManager(12036):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
06-24 05:28:36.257: E/WindowManager(12036):     at dalvik.system.NativeStart.main(Native  Method)
06-24 05:28:36.257: D/AndroidRuntime(12036): Shutting down VM
06-24 05:28:36.257: W/dalvikvm(12036): threadid=1: thread exiting with uncaught exception (group=0x40aae210)
06-24 05:28:36.267: E/AndroidRuntime(12036): FATAL EXCEPTION: main
06-24 05:28:36.267: E/AndroidRuntime(12036): java.lang.IllegalArgumentException: View not attached to window manager
06-24 05:28:36.267: E/AndroidRuntime(12036):    at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:587)
06-24 05:28:36.267: E/AndroidRuntime(12036):    at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:324)
06-24 05:28:36.267: E/AndroidRuntime(12036):    at android.view.WindowManagerImpl$CompatModeWrapper.removeView(WindowManagerImpl.java:151)
06-24 05:28:36.267: E/AndroidRuntime(12036):    at android.app.Dialog.dismissDialog(Dialog.java:321)
06-24 05:28:36.267: E/AndroidRuntime(12036):    at android.app.Dialog$1.run(Dialog.java:119)
06-24 05:28:36.267: E/AndroidRuntime(12036):    at android.app.Dialog.dismiss(Dialog.java:306)
06-24 05:28:36.267: E/AndroidRuntime(12036):    at com.iteadstudio.Login$LoginProses.onPostExecute(Login.java:177)
06-24 05:28:36.267: E/AndroidRuntime(12036):    at com.iteadstudio.Login$LoginProses.onPostExecute(Login.java:1)
06-24 05:28:36.267: E/AndroidRuntime(12036):    at android.os.AsyncTask.finish(AsyncTask.java:602)
06-24 05:28:36.267: E/AndroidRuntime(12036):    at android.os.AsyncTask.access$600(AsyncTask.java:156)
06-24 05:28:36.267: E/AndroidRuntime(12036):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
06-24 05:28:36.267: E/AndroidRuntime(12036):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-24 05:28:36.267: E/AndroidRuntime(12036):    at android.os.Looper.loop(Looper.java:137)
06-24 05:28:36.267: E/AndroidRuntime(12036):    at android.app.ActivityThread.main(ActivityThread.java:4441)
06-24 05:28:36.267: E/AndroidRuntime(12036):    at java.lang.reflect.Method.invokeNative(Native Method)
06-24 05:28:36.267: E/AndroidRuntime(12036):    at 

java.lang.reflect.Method.invoke(Method.java:511)
06-24 05:28:36.267: E/AndroidRuntime(12036):    at  

com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
06-24 05:28:36.267: E/AndroidRuntime(12036):    at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
06-24 05:28:36.267: E/AndroidRuntime(12036):    at dalvik.system.NativeStart.main(Native Method)

登录.java

 class LoginProses extends AsyncTask<String, String, String> { //line 110
    protected void onPreExecute() {..} //line 117
    protected String doInBackground(String... args) {...} //line 128
    protected void onPostExecute(String file_url) {
            // dismiss the dialog once done
    pDialog.dismiss(); // line 177
    }
4

0 回答 0