使用EditaDatos
按鈕功能,自動破壞方法書記官長的運作,已經工作沒有問題java.lang.NumberFormatException:無效長:「空」
MyDB.java
public void addPersona(Personas personas) {
ContentValues values = new ContentValues();
values.put(DBTables.EntradasTablas.COLUMN_DOCUMENTO, personas.getDocumento());
values.put(DBTables.EntradasTablas.COLUMN_NOMBRE, personas.getNombre());
values.put(DBTables.EntradasTablas.COLUMN_DIRECCION, personas.getDireccion());
values.put(DBTables.EntradasTablas.COLUMN_TEL, personas.getTel());
values.put(DBTables.EntradasTablas.COLUMN_EMAIL, personas.getEmail());
values.put(DBTables.EntradasTablas.COLUMN_PASS, personas.getPass());
SQLiteDatabase db = getWritableDatabase();
db.insert(DBTables.EntradasTablas.TABLA_NOMBRE, null, values);
db.close();
}
public Cursor personaPorId(long id) {
SQLiteDatabase db = getWritableDatabase();
String query = "SELECT * FROM " + DBTables.EntradasTablas.TABLA_NOMBRE + " WHERE " + DBTables.EntradasTablas.COLUMN_DOCUMENTO + " = " + id + ";";
Cursor c = db.rawQuery(query, null);
if (c != null) {
c.moveToFirst();
}
return c;
}
和然後,從所述片段我使用意圖來創建活動並通過數據
Cuenta.java
public class Cuenta extends android.support.v4.app.Fragment {
EditText EtEditDocu;
Button EditaDatos;
View vista;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
vista = inflater.inflate(R.layout.fragment_cuenta, container, false);
EtEditDocu = (EditText) vista.findViewById(R.id.EtEditDocu);
EditaDatos = (Button) vista.findViewById(R.id.EditaDatos);
Typeface Titulos = Typeface.createFromAsset(getActivity().getAssets(), "fonts/EaDesignerBold.ttf");
TituloActualizar.setTypeface(Titulos);
EditaDatos.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intento = new Intent(getActivity(), Registro.class);
EtEditDocu = (EditText) vista.findViewById(R.id.EtEditDocu);
intento.putExtra("documento", EtEditDocu.getText().toString());
startActivity(intento);
}
});
return vista;
}
}
Registro.java
public class Registro extends ActionBarActivity {
MyDB MyDB;
TextView Registrate;
EditText EtDocuReg;
EditText EtNombReg;
EditText EtDirecReg;
EditText EtTelReg;
EditText EtEmailReg;
EditText EtPassReg;
Button Registrar;
int idglobal;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registro);
Registrate = (TextView) findViewById(R.id.Registrate);
EtDocuReg = (EditText) findViewById(R.id.EtDocuReg);
EtNombReg = (EditText) findViewById(R.id.EtNombReg);
EtDirecReg = (EditText) findViewById(R.id.EtDirecReg);
EtTelReg = (EditText) findViewById(R.id.EtTelReg);
EtEmailReg = (EditText) findViewById(R.id.EtEmailReg);
EtPassReg = (EditText) findViewById(R.id.EtPassReg);
MyDB = new MyDB(this, null, null, 1);
Personas persona = new Personas();
Intent intento = getIntent(); // intent creado anteriormente
String Id = intento.getStringExtra("documento");
long Documento = Long.parseLong(Id);
Cursor c = MyDB.personaPorId(Documento);
EtDocuReg.setText(c.getString(c.getColumnIndexOrThrow("documento")));
EtNombReg.setText(c.getString(c.getColumnIndexOrThrow("nombre")));
EtDirecReg.setText(c.getString(c.getColumnIndexOrThrow("direccion")));
EtTelReg.setText(c.getString(c.getColumnIndexOrThrow("telefono")));
EtEmailReg.setText(c.getString(c.getColumnIndexOrThrow("email")));
EtPassReg.setText(c.getString(c.getColumnIndexOrThrow("contraseña")));
idglobal = c.getInt(c.getColumnIndexOrThrow("_id"));
Typeface Titulos = Typeface.createFromAsset(Registrate.getContext().getAssets(), "fonts/EaDesignerBold.ttf");
Registrate.setTypeface(Titulos);
}
public void Registrar(View view) {
Personas usuario = new Personas(Integer.parseInt(EtDocuReg.getText().toString()), EtNombReg.getText().toString(), EtDirecReg.getText().toString(), EtTelReg.getText().toString(), EtEmailReg.getText().toString(), EtPassReg.getText().toString());
MyDB.addPersona(usuario);
limpiarCampos();
Confirmacion();
}
public void limpiarCampos() {
EtDocuReg.setText("");
EtNombReg.setText("");
EtDirecReg.setText("");
EtTelReg.setText("");
EtEmailReg.setText("");
EtPassReg.setText("");
}
public void Confirmacion() {
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
dlgAlert.setMessage("Se ha agregado exitosamente!");
dlgAlert.setTitle("Agregar Persona");
dlgAlert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//dismiss the dialog
}
});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
}
這是錯誤
12-31 13:10:42.426 20428-20428/com.example.leonardo.odontoexpress E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.leonardo.odontoexpress/com.example.leonardo.odontoexpress.Registro}: java.lang.NumberFormatException: Invalid long: "null"
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
at android.app.ActivityThread.access$600(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5392)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NumberFormatException: Invalid long: "null"
at java.lang.Long.invalidLong(Long.java:125)
at java.lang.Long.parseLong(Long.java:342)
at java.lang.Long.parseLong(Long.java:319)
at com.example.leonardo.odontoexpress.Registro.onCreate(Registro.java:49)
at android.app.Activity.performCreate(Activity.java:5122)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
at android.app.ActivityThread.access$600(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5392)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)