일부 코드는 구문 도움이 될하지만 기본적으로
if ("".equals(text) // where text is the text that you get from an EditText or wherever you get it
{ // give message to enter valid text; }
또한, 당신은 try/catch
와 서라운드 수 있으며, NumberFormatException이를 잡아 내 응용 프로그램이 충돌합니다. 같은 예외가 발생 Ans By의 가
시도에 코드를 넣어 SIMPLE-이다 { }
및
캐치()
블록 이 코드는 잘랐다.이 작품은 나를 위해.
public void setAge(String age) {
final Calendar c = Calendar.getInstance();
int yearCurrent = c.get(Calendar.YEAR);
try {
int yearPrev = (int) Integer.parseInt(age.substring(0, 4));//this line was causing the error
int ageYear=yearCurrent-yearPrev;
ageUser="Age : "+Integer.toString(ageYear);
}
catch(NumberFormatException numberEx) {
System.out.print(numberEx);
}
}