Error calling another Activity

Asked

Viewed 23 times

0

I’m creating an app for launching student frequency. The app features web service communication.

By clicking enter button:

  1. The app will check if you have internet connection to update the teacher data in Sqlite, if you have it will access the web service method return the teacher found and soon after update or insert in the Android database.
  2. The login must be validated in the Android database, if it finds, it returns the data and compares with the user texts and password editext, if true it opens the Activity menu. That’s when the application closes with error.

Class where you have the button click method

public class Login extends Activity {

ProfessorWS professorWS = new ProfessorWS();
Professor professor = new Professor();
ProfessorDAO professorDAO = new ProfessorDAO(this);
private EditText edUsuario, edSenha;
VerificaConexao verificaConexao = new VerificaConexao();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    edUsuario = (EditText) findViewById(R.id.edUsuario);
    edSenha = (EditText) findViewById(R.id.edSenha);

}

public void btEntrarOnClick (View view){

if (verificaConexao.verificaConexao(this)){

   String msg = getString(R.string.dlg_msg);
    String titulo = getString(R.string.dlg_titulo);

    final ProgressDialog dialog = ProgressDialog.show(this, titulo, msg);

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>();
                params.put("user", edUsuario.getText().toString());
                params.put("senha", edSenha.getText().toString());

                professor = professorWS.buscarProfessor(params);
                professorDAO.insereProfessor(professor);

            } catch (Exception e) {
            } finally {
                dialog.dismiss();
            }
        }
    }).start();
}

  if (edUsuario.getText().toString().equals("")||edSenha.getText().toString().equals(""))
        Toast.makeText(this,"Usuario ou senha não informados!", Toast.LENGTH_SHORT).show();


   professor= professorDAO.buscarProfessorNoBanco(edUsuario.getText().toString(),edSenha.getText().toString());


     if(professor.getCodProfessor() == null)
        Toast.makeText(this,"Usuário não encontrado! Obs: o primeiro acesso deve esta conectado a rede", Toast.LENGTH_SHORT).show();
    else  if (professor.getUsuario().equals(edUsuario.getText().toString()) || professor.getSenha().equals(edSenha.getText().toString())) {
         Intent intent = new Intent(this, Menu.class);
         startActivity(intent);
     } else
         Toast.makeText(this,"Usuário ou senha incorreto", Toast.LENGTH_SHORT).show();

}

DAO class validating data

public class ProfessorDAO {

private SQLiteDatabase dataBase;
private BancoDados bancoDados;

public ProfessorDAO(Context context) {
    bancoDados = new BancoDados(context);
}

public String insereProfessor(Professor professor) {
    ContentValues valores;
    long resultado = 1;

    dataBase = bancoDados.getWritableDatabase();
    valores = new ContentValues();
    valores.put("CODPROF", professor.getCodProfessor());
    valores.put("NOME", professor.getNomeProfessor());
    valores.put("USUARIO", professor.getUsuario());
    valores.put("SENHA", professor.getSenha());

    resultado = dataBase.replaceOrThrow("PROFESSOR", null, valores);
    dataBase.close();

    if (resultado == -1)
        return "Erro de registro";
    else
        return "Registro Inserido com sucesso";

}


public Professor buscarProfessorNoBanco(String usuario, String senha) {


    Cursor cursor = dataBase.query("PROFESSOR", null, "USUARIO = ? AND SENHA = ?", new String[]{usuario, senha}, null, null, null);
    Professor professor = null;
    if (cursor.moveToNext()) {
        professor = new Professor();
        professor.setCodProfessor(cursor.getString(0));
        professor.setNomeProfessor(cursor.getString(1));
        professor.setUsuario(cursor.getString(2));
        professor.setSenha(cursor.getString(3));
    } else {
        Log.i("Erro:", "Erro no if do cursor");
    }
    cursor.close();
  return professor;
    }
}

Error

E/AndroidRuntime: FATAL EXCEPTION: main
                                                                      Process: feol.com.br.diarioclasse, PID: 20105
                                                                      java.lang.IllegalStateException: Could not execute method of the activity
                                                                          at android.view.View$1.onClick(View.java:4025)
                                                                          at android.view.View.performClick(View.java:4785)
                                                                          at android.view.View$PerformClick.run(View.java:19884)
                                                                          at android.os.Handler.handleCallback(Handler.java:739)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                          at android.os.Looper.loop(Looper.java:135)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5343)
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at java.lang.reflect.Method.invoke(Method.java:372)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
                                                                       Caused by: java.lang.reflect.InvocationTargetException
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at java.lang.reflect.Method.invoke(Method.java:372)
                                                                          at android.view.View$1.onClick(View.java:4020)
                                                                          at android.view.View.performClick(View.java:4785) 
                                                                          at android.view.View$PerformClick.run(View.java:19884) 
                                                                          at android.os.Handler.handleCallback(Handler.java:739) 
                                                                          at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                          at android.os.Looper.loop(Looper.java:135) 
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5343) 
                                                                          at java.lang.reflect.Method.invoke(Native Method) 
                                                                          at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 
                                                                       Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.database.Cursor android.database.sqlite.SQLiteDatabase.query(java.lang.String, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String, java.lang.String, java.lang.String)' on a null object reference
                                                                          at feol.com.br.diarioclasse.ProfessorDAO.buscarProfessorNoBanco(ProfessorDAO.java:46)
                                                                          at feol.com.br.diarioclasse.Login.btEntrarOnClick(Login.java:68)
                                                                          at java.lang.reflect.Method.invoke(Native Method) 
                                                                          at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                          at android.view.View$1.onClick(View.java:4020) 
                                                                          at android.view.View.performClick(View.java:4785) 
                                                                          at android.view.View$PerformClick.run(View.java:19884) 
                                                                          at android.os.Handler.handleCallback(Handler.java:739) 
                                                                          at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                          at android.os.Looper.loop(Looper.java:135) 
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5343) 
                                                                          at java.lang.reflect.Method.invoke(Native Method) 
                                                                          at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 
  • Cade your debug?

  • What is the error? On which line is occurring?

  • @Pabloalmeida because it is without the debug of his code has no way of knowing! It may be the activity that he is calling that does not exist! but it’s kind of hard to know

  • I put the error in the question

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.