You try to call a method (setText())
, on vwfecha1
but you haven't initialized it yet so it is null
. Change your onCreate()
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Date date = new Date(0);
String dateTime = DateFormat.getDateTimeInstance().format(date);
vwfecha1 = (TextView) findViewById(R.id.idOfvwfecha1); // add this line with the appropriate id
vwfecha1.setText(dateTime);
Also, I'm not sure what this line in your onClick()
will give
v.getId()==findViewById(R.id.enviar).getId()
but it can simply be
v.getId()==R.id.enviar
It looks like it will do the same thing but you are taking extra, unnecessary steps