0

onPostExecute 出了什么问题。它显示了该方法的错误。ProgressDialog 工作正常。json 和数据库处理程序都正常工作。对 ProgressDialog 进行了相同的简化。

class ProcessBalance  extends AsyncTask<String, Void, List<String>> {

        private Dialog dialog;

        /**
         * Before starting background thread
         * Show Progress Bar Dialog
         * */
        @Override
        protected void onPreExecute() {

             final Dialog dialog = new Dialog(UserhomeActivity.this);
             dialog.setTitle("test");
             dialog.setContentView(R.layout.dialoglayout);
             dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
             Button btnDismiss = (Button)dialog.getWindow().findViewById(R.id.dismiss);
           //  TextView balview = (TextView) dialog.findViewById(R.id.textView1);
        //     balview.setText("Please wait for the balance.");

             //http://www.mkyong.com/android/android-custom-dialog-example/

             btnDismiss.setOnClickListener(new OnClickListener(){

               public void onClick(View v) {
                   dialog.dismiss();
               }});

             dialog.show();
        }

        /**
         * Downloading file in background thread
         * */
        @Override
        protected List<String> doInBackground(String... args0) {
        //  DatabaseHandler db = new DatabaseHandler(getApplicationContext());
            //HashMap<String, String> user = db.getUserDetails();
            UserFunctions userFunction = new UserFunctions();
            //JSONObject json = userFunction.getBalance(user.get("mobile_no"));
            JSONObject json = userFunction.getBalance("1234567890");
            List<String> LIST = new ArrayList<String>();
            try {
                if (json.getString(KEY_SUCCESS) != null) {
                    String res = json.getString(KEY_SUCCESS);
                    LIST.add(json.getString("success"));
                    LIST.add(json.getString("balance"));
            }

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

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

            return LIST;
        }


        /**
         * After completing background task
         * Dismiss the progress dialog
         * **/

        protected void onPostExecute(List<String> result) {

            String responseCodestr = result.get(0);
            final int responseCode = Integer.parseInt(responseCodestr);
            String bal = result.get(1);
            TextView balview = (TextView) dialog.findViewById(R.id.textView1);

            if(responseCode==1){
                 balview.setText("test "+bal);
            } else {
                  balview.setText("test2");
            }

        }

      }
4

2 回答 2

1

您有两个对话框,一个作为成员,另一个在 onPreExecute 中定义。您应该更改以下代码

    private Dialog dialog;
    @Override
    protected void onPreExecute() {

         final Dialog dialog = new Dialog(UserhomeActivity.this);

为了这:

    private final Dialog dialog;
    @Override
    protected void onPreExecute() {

         this.dialog = new Dialog(UserhomeActivity.this);
于 2013-07-26T09:56:16.090 回答
0

问题是您已经两次声明了对话框。

一个是在 onPreExecute 之前

 private Dialog dialog;

一个在 onPreExecute 里面

final Dialog dialog = new Dialog(UserhomeActivity.this);

您正在初始化的对话框是第二个,您尝试在 onPostExceute 中使用的对话框是第一个。

解决方案是

改变

final Dialog dialog = new Dialog(UserhomeActivity.this);

dialog = new Dialog(UserhomeActivity.this);
于 2013-07-26T09:57:18.477 回答