android中的android.view.ViewRootImpl $ CalledFromWrongThreadException

时间:2013-02-28 13:09:45

标签: android android-asynctask

我收到了这个错误。我用Google搜索并编辑了我的doInBackground函数,我删除了doInBackground中的视图,但我仍然收到此错误。有什么问题可以帮我吗?

private class MessageProgressBar extends AsyncTask<Void, Integer, Void>{

    /** This callback method is invoked, before starting the background process */
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        /** Creating a progress dialog window */
        mProgressDialog = new ProgressDialog(Messages.this);

        /** Close the dialog window on pressing back button */
        mProgressDialog.setCancelable(true);

        /** Setting a horizontal style progress bar */
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

        /** Setting a message for this progress dialog
         * Use the method setTitle(), for setting a title
         * for the dialog window
         *  */
        mProgressDialog = ProgressDialog.show(Messages.this, 
                "Mesaj Gönderilyor", "Lütfen bekleyin...");



    }

    /** This callback method is invoked on calling execute() method
     * on an instance of this class */
    @Override
    protected Void doInBackground(Void...params) {
        String createdReplyResult=ReplyMessageWS(msgid[0], replyText.getText().toString(), mid, targetmid);
        parseReplyResult(createdReplyResult);   

        if(replyridfordevice[0]>1){
            replydbInstance.insertReplies(replyridfordevice[0], msgid[0], replyText.getText().toString(),replydatefordevice[0], mid, targetmid);

        }


        return null;
    }

    /** This callback method is invoked when publishProgress()
     * method is called */
    @Override
    protected void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);
        mProgressDialog.setProgress(mProgressStatus);

    }

    /** This callback method is invoked when the background function
     * doInBackground() is executed completely */
    @Override
    protected void onPostExecute(Void result) { 

        replyText.setText("");
        startActivity(getIntent());

        mProgressDialog.dismiss();


    }
}



    private String ReplyMessageWS(int msgid,String replydesc,int repliedfrom,int repliedto) {

    String NAMESPACE = "http://ws.apache.org/axis2";
    String URL = "http://212.154.125.220:8080/MobileMerchMessage/services/messagesWS?wsdl";
    String METHOD_NAME = "replyMessage";
    String myResult = null;

    String SOAP_ACTION = NAMESPACE + METHOD_NAME;
    SoapObject result;
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    request.addProperty("msgid",msgid);
    request.addProperty("replydesc",replydesc);
    request.addProperty("repliedfrom",repliedfrom);
    request.addProperty("repliedto",repliedto);

    // Parameter for Method
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    // envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    try {
        androidHttpTransport.call(SOAP_ACTION, envelope);
        result = (SoapObject) envelope.bodyIn;
        myResult = result.getProperty("return").toString();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return myResult;

}

public void insertReplies(int rid,int msgid,String replydesc, String replydate, int repliedfrom,int repliedto) {
    SQLiteDatabase myDatabase = this.getWritableDatabase();

            String query = "INSERT INTO Replies (_id,msgid,replydesc,replydate,repliedfrom,repliedto) "+
                           " VALUES ("+rid+","+msgid+",'"+replydesc+"','"+replydate+"',"+repliedfrom+","+repliedto+")";
            SQLiteStatement st = myDatabase.compileStatement(query);

    try {
        st.execute();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    myDatabase.close();
    Log.i("insert","insert Replies completed");
}

1 个答案:

答案 0 :(得分:2)

我猜你的replydbInstance.insertReplies()来电正在编辑某些观点......

我们只能猜测这些信息,请发布错误 stacktrace