java.lang.RuntimeException: Can not create handler inside thread that has not called Looper.prepare ();

0

What should I do to solve this problem?

  private void callServer(final String method, final String data){

        new Thread(){

            public void run(){
               asw = Connection.getSetDataWeb("http://192.168.1.20/renan/process.php", method, data);

                if (data.isEmpty()){
                    degenerateJson(asw);
               }

                if(asw.equals("3")){
                    makeText(MainActivity.this, "Código da igreja inesistente, por favor escreva um código válido.", LENGTH_SHORT).show();
                }else if (asw.equals("2")){
                    makeText(MainActivity.this, "Senha incorreto, por favor escreva uma senha válida.", LENGTH_SHORT).show();
                }else if (asw.equals("1"))
                {
                    makeText(MainActivity.this, "E-mail incorreto, por favor escreva um email válido.", LENGTH_SHORT).show();
                }else{
                    Intent it = new Intent(MainActivity.this, MC_Home.class);
                    it.putExtra("email", email.getText().toString());
                    it.putExtra("cod_igrej", cod_igrej.getText().toString());
                    startActivity(it);
                }
            }
        }.start();
       }

Logcat:

05-22 14:33:48.578  28186-28305/com.example.hotsystems.hs_celulas E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-121
    Process: com.example.hotsystems.hs_celulas, PID: 28186
    android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
            at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6094)
            at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:824)
            at android.view.View.requestLayout(View.java:16431)
            at android.view.View.requestLayout(View.java:16431)
            at android.view.View.requestLayout(View.java:16431)
            at android.view.View.requestLayout(View.java:16431)
            at android.view.View.requestLayout(View.java:16431)
            at android.view.View.requestLayout(View.java:16431)
            at android.view.View.requestLayout(View.java:16431)
            at android.view.View.requestLayout(View.java:16431)
            at android.view.View.requestLayout(View.java:16431)
            at android.widget.TextView.checkForRelayout(TextView.java:6594)
            at android.widget.TextView.setText(TextView.java:3813)
            at android.widget.TextView.setText(TextView.java:3671)
            at android.widget.TextView.setText(TextView.java:3646)
            at android.app.ProgressDialog.setMessage(ProgressDialog.java:316)
            at com.example.hotsystems.hs_celulas.MainActivity$3.run(MainActivity.java:140)

Using AsyncTaks, but I have not tested it yet, it is giving error when calling another activity, if in case everything is correct.

package com.example.hotsystems.hs_celulas;

import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; import android.os.AsyncTask;

public class Activity_Enter extends AsyncTask {     private Context context;     private ProgressDialog progress;

public Atividade_Entrar(Context context){
    this.context = context;
}

protected void onPreExecute(){
    ProgressDialog progresso = new ProgressDialog(context);
    progresso.setMessage("Aguarde...");
    progresso.show();
}
protected String doInBackground(String... asw){
    if(asw.equals("3"))
        progresso.setMessage("Código da igreja inesistente, por favor escreva um código válido.");
    else if (asw.equals("2")){
        progresso.setMessage("Senha incorreto, por favor escreva uma senha válida.");
        // makeText(MainActivity.this, "Senha incorreto, por favor escreva uma senha válida.", LENGTH_SHORT).show();
    }else if (asw.equals("1"))
    {
        progresso.setMessage("E-mail incorreto, por favor escreva um email válido.");
        // makeText(MainActivity.this, "E-mail incorreto, por favor escreva um email válido.", LENGTH_SHORT).show();
    }

    return null;
}
protected void onProgressUpdate(){

}
protected void onPostExecute(){
    progresso.setMessage("Seja Bem vindo.");
    progresso.show();

    Intent it = new Intent(context, MC_Home.class);
    startActivity(it);
    progresso.dismiss();

}

}

    
asked by anonymous 22.05.2015 / 19:41

0 answers