致命异常:AsyncTask#1 java.lang.RuntimeException:执行doInBackground()

时间:2017-08-03 17:49:39

标签: java android android-asynctask

即时通讯登录,昨天一切正常,但今天安卓工作室给了我那个错误

{08-03 14:29:07.894 13703-14015 / complete.lyne.myapplication E / AndroidRuntime:FATAL EXCEPTION:AsyncTask#1                                                                              过程:complete.lyne.myapplication,PID:13703                                                                              java.lang.RuntimeException:执行doInBackground()时发生错误                                                                                  在android.os.AsyncTask $ 3.done(AsyncTask.java:318)                                                                                  在java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)                                                                                  at java.util.concurrent.FutureTask.setException(FutureTask.java:223)                                                                                  在java.util.concurrent.FutureTask.run(FutureTask.java:242)                                                                                  在android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:243)                                                                                  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)                                                                                  at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:607)                                                                                  在java.lang.Thread.run(Thread.java:761)                                                                               引起:java.lang.IllegalArgumentException:意外网址:192.168.1.100/lyne/logar.php                                                                                  在okhttp3.Request $ Builder.url(Request.java:143)                                                                                  at complete.lyne.myapplication.Conexao.postDados(Conexao.java:23)                                                                                  at complete.lyne.myapplication.Login $ SolicitaDados.doInBackground(Login.java:91)                                                                                  at complete.lyne.myapplication.Login $ SolicitaDados.doInBackground(Login.java:87)                                                                                  在android.os.AsyncTask $ 2.call(AsyncTask.java:304)                                                                                  在java.util.concurrent.FutureTask.run(FutureTask.java:237)                                                                                  在android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:243)                                                                                  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)                                                                                  at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:607)                                                                                  在java.lang.Thread.run(Thread.java:761) 08-03 14:29:08.039 13703-13756 / complete.lyne.myapplication D / OpenGLRenderer:0xA5420f00(RippleDrawable)上的endAllActiveAnimators,句柄为0x8e8d5af0}

以下是帐户创建错误

package complete.lyne.myapplication;

import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Cadastro extends AppCompatActivity {

EditText criarNome, criarSobre, criarEmail, criarSenha;
TextView refpLogin;
Button btCriar;

String url = "";
String parametro = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cadastro);

    criarNome = (EditText)findViewById(R.id.criarNome);
    criarSobre = (EditText)findViewById(R.id.criarSobre);
    criarEmail = (EditText)findViewById(R.id.criarEmail);
    criarSenha = (EditText)findViewById(R.id.criarSenha);
    btCriar = (Button)findViewById(R.id.btCriar);
    refpLogin = (TextView)findViewById(R.id.refpLogin);

    refpLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent abreLogin = new Intent(Cadastro.this, Login.class);
            startActivity(abreLogin);
        }
    });

    btCriar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            ConnectivityManager connectivityManager = (ConnectivityManager)
                    getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

            if (networkInfo != null && networkInfo.isConnected()) {

                String criaNome = criarNome.getText().toString();
                String criaSobre = criarSobre.getText().toString();
                String criaEmail = criarEmail.getText().toString();
                String criaSenha = criarSenha.getText().toString();


                if(criarNome.getText().length()==0) {
                    criarNome.setError("Por favor insira seu Nome.");
                } else if(criarSobre.getText().length()==0) {
                    criarSobre.setError("Por favor insira seu Sobrenome.");
                } else if(criarEmail.getText().length()==0) {
                    criarEmail.setError("Por favor insira seu endereço de Email.");
                } else if(criarSenha.getText().length()==0) {
                    criarSenha.setError("Por favor insira uma senha.");
                } else if(criarSenha.getText().length()<8) {
                    criarSenha.setError("Sua senha deve conter no mínimo 8 caracteres.");
                } else if (criaNome.isEmpty() && criaSobre.isEmpty() && criaEmail.isEmpty() && criaSenha.isEmpty()) {
                    Toast.makeText(getApplicationContext(), "Nenhum campo pode ficar vazio.", Toast.LENGTH_LONG).show();
                } else {

                    // Casa
                    url = "192.168.1.100/lyne/registrar.php";

                    // Badran
                    // url = "http://172.16.2.15/lyne/logar.php";

                    parametro = "nome" + criaNome + "&sobrenome" + criaSobre + "&email=" + criaEmail + "&senha=" + criaSenha;

                    new SolicitaDados().execute(url);

                }

            } else {
                Toast.makeText(getApplicationContext(), "Nenhuma conexão com a Internet foi encontrada.", Toast.LENGTH_LONG).show();
            }

        }
    });

}

private class SolicitaDados extends AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... urls) {

        return Conexao.postDados(urls[0], parametro);

    }

    @Override
    protected void onPostExecute(String resultado) {

        if(resultado.contains("email_erro")) {
            criarEmail.setError("Esse endereço de Email já está cadastrado!");
        } else if (resultado.contains("registro_ok")) {
                Intent abreLogin2 = new Intent(Cadastro.this, Login.class);
                startActivity(abreLogin2);
            } else {
                Toast.makeText(getApplicationContext(), "Ocorreu algum erro", Toast.LENGTH_LONG).show();
            }
        }
    }

@Override
protected void onPause() {
    super.onPause();
    finish();
}


}

这是登录

package complete.lyne.myapplication;

import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.io.IOException;

public class Login extends AppCompatActivity {

EditText loginEmail, loginSenha;
Button btLogar;
TextView refCadastrar;

String url = "";
String parametro = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);

    loginEmail = (EditText)findViewById(R.id.loginEmail);
    loginSenha = (EditText)findViewById(R.id.loginSenha);
    btLogar = (Button)findViewById(R.id.btLogar);
    refCadastrar = (TextView)findViewById(R.id.refCadastrar);

    refCadastrar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent abreCadastro = new Intent(Login.this, Cadastro.class);
            startActivity(abreCadastro);
        }
    });

    btLogar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            ConnectivityManager connectivityManager = (ConnectivityManager)
                    getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

            if (networkInfo != null && networkInfo.isConnected()) {

                String email = loginEmail.getText().toString();
                String senha = loginSenha.getText().toString();

                if(email.isEmpty() && senha.matches(".*[a-z].*")) {
                    loginEmail.setError("Insira seu endereço de Email.");
                } else if (email.matches(".*[a-z].*") && senha.isEmpty()) {
                    loginSenha.setError("Insira sua Senha.");
                } else if (email.isEmpty() && senha.isEmpty()) {
                        Toast.makeText(getApplicationContext(), "Nenhum campo pode ficar vazio.", Toast.LENGTH_LONG).show();
                } else {

                    // Casa
                    url = "192.168.1.100/lyne/logar.php";

                    // Badran
                    // url = "http://172.16.2.15/lyne/logar.php";

                    parametro = "email=" + email + "&senha=" + senha;

                    new SolicitaDados().execute(url);

                }

            } else {
                Toast.makeText(getApplicationContext(), "Nenhuma conexão com a Internet foi encontrada.", Toast.LENGTH_LONG).show();
            }


        }
    });
    }

private class SolicitaDados extends AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... urls) {

            return Conexao.postDados(urls[0], parametro);

    }

    @Override
    protected void onPostExecute(String resultado) {

        if(resultado != null) {
            if (resultado.contains("login_ok")) {
                Intent abreHome = new Intent(Login.this, Home.class);
                startActivity(abreHome);
            } else {
                Toast.makeText(getApplicationContext(), "Usuário ou senha incorretos.", Toast.LENGTH_LONG).show();
            }
        }
    }


}

@Override
protected void onPause() {
    super.onPause();
    finish();
}

}

1 个答案:

答案 0 :(得分:0)

您的堆栈跟踪会告诉您问题。尝试解析url时,您有一个非法的参数异常:

192.168.1.100/lyne/logar.php