即使将setText设置为类似daysTV.setText“ 5”这样的硬数字,daysTV也始终为null,但是如果我将它写在try {}旁边,则它会起作用

问题描述

这是我的代码,我试图从数据库获取两个日期之间的天数,startingDateTV = 1-10-2020,currentDate = 06-10-2020,所有值都将写入,但只有setText到daysTV不是加工 即使我设置了一个硬文本或数字(例如daysTV.setText(“ 5”)),其值仍为null,但不会使应用崩溃。

SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("dd/MM/yyyy",Locale.getDefault());
try {
 Date date1= simpleDateFormat1.parse(startingDateTV.getText().toString());
 Date date2= simpleDateFormat1.parse(currentDateTV.getText().toString());

 long startDate= date1.getTime();
 long endDate= date2.getTime();

 Period period = new Period(startDate,endDate,PeriodType.yearMonthDay());
 int years = period.getYears();
 int months = period.getMonths();
 int days = period.getDays();

 daysTV.setText(days);

 } catch (ParseException e) {
   e.printstacktrace();
 }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)