I have a layout that will display a TextView
which is used to display a ticking time.I followed the codes from this link
How to Display current time that changes dynamically for every second in android
but I get an error of
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
I had the same problem here but I fixed it
Intent extras null on configuration change
Here are the Java codes
void clockTicking(){
final CountDownTimer newtimer = new CountDownTimer(1000000000, 1000) {
public void onTick(long millisUntilFinished) {
timeDisplay = (TextView)findViewById(R.id.txtTime);
Calendar c = Calendar.getInstance();
timeDisplay.setText(c.get(Calendar.HOUR)+":"+c.get(Calendar.MINUTE)+":"+c.get(Calendar.SECOND)+" PM");
}
public void onFinish() {
}
};
newtimer.start();