2017-08-03 127 views
0

即时通讯做的apllication来登录,一切工作昨天发生了错误,但今天的Android工作室是给我的错误致命异常:#的AsyncTask 1了java.lang.RuntimeException:在执行doInBackground()

{08 -03 14:29:07.894 13703-14015/complete.lyne.myapplication E/AndroidRuntime:致命异常:AsyncTask#1 进程:complete.lyne.myapplication,PID:13703 java.lang.RuntimeException:执行时发生错误doInBackground() at android.os.AsyncTask $ 3.done(AsyncTask.java:318) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)(FutureTask.java:223) at java.util.concurrent.FutureTask.run(FutureTask.java:242) at 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) at java.lang.Thread .run(Thread.java:761) 引起:java.lang.IllegalArgumentException:意外url:192.168.1.100/lyne/logar.php at 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) at android.os.AsyncTask $ 2.call(AsyncTask.java:304) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:243) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 在java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:607) 在ja va.lang.Thread.run(Thread.java:761) 08-03 14:29:08.039 13703-13756/complete.lyne.myapplication d/OpenGLRenderer:带手柄0x8e8d5af0上0xa5420f00 endAllActiveAnimators(RippleDrawable)}

这里是帐户创建

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(); 
} 

} 

回答

0

你的堆栈跟踪告诉你的问题。试图解析url时出现非法参数异常:

192.168.1.100/lyne/logar.php 
+0

谢谢,我修好了,出了什么问题哈哈 – Higor

+0

没问题。很高兴我能帮上忙 – anomeric

相关问题