いくつかのコードでは、構文に役立つだろうが、基本的に
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をキャッチマイクラッシュするアプリケーション。同様に、例外が発生回答 が
試みのコードを入れ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);
}
}