Android - Show Current Date in my Android Studio Activity and send it to SQLite

0

Greetings friends how are you, I would like to see if you can help me with this detail for my class

I have my activity ready and I am creating my java class to show the date and time and also enter a data of an event

Code below

public class IngresoActivityEvento extends AppCompatActivity {

    TextView dia;
    TextView fecha;
    TextView hora;
    EditText evento;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ingreso_evento);

        dia = findViewById(R.id.textDia);
        fecha = findViewById(R.id.textFecha);
        hora= findViewById(R.id.textHora);
        evento= findViewById(R.id.edt_PlacaIng);
    }


    private void registrarChekIn() {
        ConexionSQLiteHelper conn=new ConexionSQLiteHelper(this,"bd_eventos",null,1);
        SQLiteDatabase db=conn.getWritableDatabase();

        ContentValues values=new ContentValues();
        values.put(Utilidades.CHEKIN_DIA,dia.getText().toString());
        values.put(Utilidades.CHEKIN_FECHA,fecha.getText().toString());
        values.put(Utilidades.CHEKIN_HORA,hora.getText().toString());
        values.put(Utilidades.CHEKIN_EVENTO,evento.getText().toString());

        Long idResultante=db.insert(Utilidades.TABLA_CHEKIN,Utilidades.CHEKIN_ID,values);
        Toast.makeText(getApplicationContext(),"Chek-In " + idResultante + " Realizado Correctamente",Toast.LENGTH_SHORT).show();
        db.close();
    }

    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn_Registrar: registrarChekIn();
        }
    }
}

hasta el momento perfecto me graba mi IDE automatico y mi EVENTO cuando se escribe en el emulador, pero no me muestra las fechas y menos envia las fechas a la base de datos.

Trate de usar dentro del onCreate este codigo

        Date d=new Date();     

        //DIA EN LETRA
        dia = findViewById(R.id.textDia);
        SimpleDateFormat di=new SimpleDateFormat("EEEE");
        String currentDateTimeStrin = di.format(d);
        dia.setText(currentDateTimeStrin);

        //FECHA COMPLETA
        fecha = findViewById(R.id.textFecha);
        SimpleDateFormat fecc=new SimpleDateFormat("DD/MM/AAAA");
        String fechacComplString = fecc.format(d);
        fecha.setText(fechacComplString);

        // HORA
        hora= findViewById(R.id.textHora);
        SimpleDateFormat ho=new SimpleDateFormat("h:mm a");
        String horaString = ho.format(d);
        hora.setText(horaString);

        evento= findViewById(R.id.edt_evento);

When launching the app in that Activity it closes, I do not know if you can orientate me to know how I do to show the data of the dates and send them to the BD

Error that shows me:

  

Caused by: java.lang.NullPointerException: Attempt to invoke virtual   method 'void android.widget.TextView.setText (java.lang.CharSequence)'   on a null object reference at   ve.com.example.technology.eventos.modules.IngresoActivityeve nto.onCreate (Income Activityevento.java:41)

I also want to include an additional field of event status but I do not know how to include it so that the user does not intervene with it, do the same as the ID does but with the Value of (A) Active because when it is included it will be activated, when it is eliminated (I) it will be inactivated and if it is Canceled it will take the value of (N) Null.

Thank you in advance.

    
asked by Gerardo 28.11.2017 в 08:14
source

0 answers