当前位置: 首页 > 知识库问答 >
问题:

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

殳智志
2023-03-14

我做了一个应用程序登录,一切都是正常的昨天,但今天android工作室给了我这个错误

{08-03 14:29:07.894 137 03-14015/Complete.Lyne.MyApplication E/AndroidRuntime:致命异常:AsyncTask#1进程:Complete.Lyne.MyApplication,PID:13703 java.lang.RuntimeException:在Android.os.AsyncTask$3执行doInBackground()时出错。Done(AsyncTask.java:318)在java.util.concurrent.FutureTask.FinishCompletion(FutureTask.java:354)在在complete.lyne.myapplication.login中登录$solicitadados.doinbackground(login.java:87)在android.os.asynctask中登录$solicitadados.doinbackground(login.java:87)在android.os.asynctask中登录$solicitadados.doinbackground(login.java:87)在java.util.concurrent.futuretask.run(futuretask.java:237)在android.os.asynctask中登录在java.util.concurrent.ThreadPoolExecutor.RunWorker(ThreadPoolExecutor.java:1133) 在java.util.concurrent.ThreadPoolExecutor$worker.run(ThreadPoolExecutor.java:607) 在java.lang.thread.run(thread.java:761) 08-03 14:29:08.039 137 03-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个答案

闻人宝
2023-03-14

堆栈跟踪会告诉您问题所在。试图解析URL时出现非法参数异常:

192.168.1.100/lyne/logar.php
 类似资料:
  • 我在android设备上构建代码时出错了。这是错误报告 05-17 09:47:16.035 17982-18134/com . example . ckw . mapku E/Android runtime:致命异常:async task # 1 05-17 09:47:16.035 17982-18134/com . example . mapku E/Android runtime:Proc

  • 我在android设备上构建代码时出错。这是错误报告 致命异常:AsyncTask#1进程:com。实例冈图,PID:1248爪哇。lang.RuntimeException:在android上执行doInBackground()时出错。操作系统。异步任务3美元。在java上完成(AsyncTask.java:304)。util。同时发生的未来任务。在java完成(FutureTask.java:

  • 早上好StackOver Flow Pros, 我需要一点帮助。我正在运行一个Android应用程序,该应用程序通过php脚本调用MySql数据库,当我运行该应用程序时,我得到一个由空指针异常导致的AsyncTask #1的致命异常错误。它说是在执行doInBackground时发生的。这是我从MyBringBack跟随的一个教程。我真的需要好好想想这件事,因为我已经想了好几天了。如果我删除/注释

  • 活动: 类 updateTwitterStatus extends AsyncTask { 这就是 LogCat 06-05 18:00:26.696: E/AndroidRuntime(1516): 致命异常: AsyncTask #2 06-05 18:00:26.696: E/AndroidRuntime(1516): java.lang.RuntimeException: 执行 doInB

  • 执行 时出错。 这是错误日志: 11-05 05:03:20.171:E/Android runtime(3171):致命异常:async task # 1 < br > 11-05 05:03:20.171:E/Android runtime(3171):Process:com . example . MySQL test,PID:3171 < br > 11-05 05:03:20.171:E

  • java.lang.RuntimeException:执行doInBackground()E/Android runtime(695)时出错:at Android . OS . async task $ 3 . done(async task . Java:200)E/Android runtime(695):at Java . util . concurrent . future task $