0

Application code is

DateTime startDate8 = DateTime.now(); 
DateTime endDate8 = new DateTime(2014, 11, 5, 15, 0);

Period period8 = new Period(startDate8, endDate8, PeriodType.dayTime());

PeriodFormatter formatter8 = new PeriodFormatterBuilder()
    .appendMinutes()
    .toFormatter(); 

tw.setText(String.format("%02d",formatter8.print(period8))); 

Application dont work. App has stopped unfortunately. What is problem in my code?

Taha Körkem
  • 774
  • 2
  • 9
  • 23

1 Answers1

1

PeriodFormatter.print() returns a String (and "%02d requires a int). I think you wanted something like

 // tw.setText(String.format("%02d",formatter8.print(period8))); 
tw.setText(formatter8.print(period8)); 

Or, parse the String to an int like

try {
    int val = Integer.parseInt(formatter8.print(period8));
    tw.setText(String.format("%02d",val));
} catch (NumberFormatException nfe) {
    nfe.printStackTrace();
}
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249