저는 안드로이드를 처음 접하며 조담 사용에 문제가 있습니다. 나는 여기에 많은 사람들과 같은 오류가 발생하고 모든 제안을 시도했지만 아무것도 나를 위해 일하고있다. 사용자가 날짜 및 시간 선택 도구에서 선택한 변수를 표시하려고합니다. 예 : 'dayNow, monthNow'등을 'timeselected'라는 하나의 결합 된 변수로 변환 한 다음 텍스트 상자로 설정하면 jodatime에서 계산을 수행 할 수 있습니다.JodaTime이 작동하지 않습니다.
DateTime dateTime = new DateTime(timeselected);
DateTimeFormatter fmt = DateTimeFormat.forPattern("dd MM yyyy" + "\n" + " h:mm a ");
String formattedtime = fmt.print(dateTime);
CalculateButton.setText(formattedtime);
// Plus some hours, minutes, and seconds to the original DateTime.
DateTimeFormatter fmt2 = DateTimeFormat.forPattern("dd MM yyyy" + "\n" + " h:mm a ");
DateTime dateTime1 = dateTime.plusHours(timeadded);
String endtimecalc = fmt2.print(dateTime1);
TextView endtime = (TextView) findViewById(endtimetextView);
endtime.setVisibility(View.VISIBLE);
endtime.setText(endtimecalc);
String timeselected = dayNow + "-" + monthNow + "-" + yearNow + " " + hourNow + ":" + minuteNow;
DateTime datetimselected = DateTime.parse(timeselected);
usertimeselection.setText((CharSequence) datetimselected.toDate());
}
});
치명적인 예외 : 주요 프로세스 : com.almac.tracker, PID : 29114 java.lang.IllegalArgumentException가 : 잘못된 형식을 다음과 같이
코드는 "2017-11- 23 T 4:56 "이"T 4:56 "에 변형되었습니다. at org.joda.time.format.DateTimeFormatter.parseDateTime (DateTimeFormatter.java:945) at org.joda.time.DateTime.parse (DateTime.java : 160) at org.joda.time.DateTime.parse (DateTime. java : 149) at com.almac.tracker.CreateLine $ 5.onClick (CreateLine.java:274) at android.view.View.performClick (View.java:6219) android.view.View $ PerformClick.run (View.java:24482) android.os.Handler.handleCallback (Handler.java:769) at android.os.Handler.dispatchMessage (Handler.java:98) at android.os.Looper.loop (루퍼 . java : 164) android.app.ActivityThread.main (ActivityThread.java:6540) at java.lang.reflect.Method.invoke (네이티브 메소드) at com.android.internal.os.Zygote $ MethodAndArgsCaller. 뛰기 (Zygote.java:240)
DateTime.parse(String str)
문서에서 com.android.internal.os.ZygoteInit.main (ZygoteInit.java:767)
이의 DUP가 있어야하지만, Joda 시간 까다로운입니다 형식에 관하여; '-'이 아닌'/'이 아닌 날짜 구성 요소를 분리해야합니다. 자세한 정보는 [the docs] (http : //joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTimeParser \ (\))를 참조하십시오. -'8-11-2017 T 4 : 16 : 00'이 필요할 수 있습니다. –
당신이 좀 걸릴 수 있다면 위의 모든 관련 코드를 추가했습니다 – Almac3