我的应用每次都崩溃,我找不到任何问题的解决方案。
代码是:
package com.example.juan.sem4;
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.Toast;
public class Registrarse extends AppCompatActivity {
EditText txtNom, txtCor, txtPas;
Button btnRegistrarse;
BD_Usuarios bd=new BD_Usuarios(this,"BD1",null,1);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registrarse);
txtNom=(EditText)findViewById(R.id.txtRegNom);
txtCor=(EditText)findViewById(R.id.txtRegCor);
txtPas=(EditText)findViewById(R.id.txtPas);
btnRegistrarse=(Button)findViewById(R.id.btnRegistrarse);
btnRegistrarse.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bd.abrir();
bd.registrarUsu(txtNom.getText().toString(),txtCor.getText().toString(),txtPas.getText().toString());
bd.cerrar();
txtCor.setText("");
txtNom.setText("");
txtPas.setText("");
txtNom.findFocus();
Toast.makeText(getApplicationContext(),"Se registro con exito",Toast.LENGTH_LONG).show();
finish();
}
});
}
}
LOGCAT显示以下问题:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
at com.example.juan.sem4.Registrarse$1.onClick(Registrarse.java:32)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
问题似乎是第32行:
bd.registrarUsu(txtNom.getText()的toString(),txtCor.getText()的toString(),txtPas.getText()的toString()。);
但老实说,我无法看到问题。