Java Code Examples for java.text.ParseException

The following are top voted examples for showing how to use java.text.ParseException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: anewjkuapp   File: Parser.java View source code 8 votes vote down vote up
public static Date parseDate(String text, String errorMsg) throws ParseException {
     if (!TextUtils.isEmpty(text)) {
         try {
	return dateFormat.parse(text);
} catch (ParseException e) {
	if(errorMsg.trim().isEmpty()) errorMsg = e.getMessage();
	else errorMsg = errorMsg+": "+e.getMessage();
	throw new ParseException(errorMsg,e.getErrorOffset());
}
     }
     return null;
 }
 
Example 2
Project: my-ministry-assistant   File: TitleAndDateAdapter.java View source code 7 votes vote down vote up
public void addItem(int id, String title, String date) {
	Calendar convertedDate = Calendar.getInstance(Locale.getDefault());
	if(!TextUtils.isEmpty(date)) {
		try {
			convertedDate.setTime(TimeUtils.dbDateFormat.parse(date));
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}
	addItem(new ItemWithDate(id, title, !TextUtils.isEmpty(date) ? createDisplayDate(convertedDate) : context.getResources().getString(R.string.no_activity)));
}
 
Example 3
Project: JerseyTest   File: CacheControlProvider.java View source code 7 votes vote down vote up
private int readIntValue(HttpHeaderReader reader, String directiveName)
        throws ParseException {
    reader.nextSeparator('=');
    int index = reader.getIndex();
    try {
        return Integer.parseInt(reader.nextToken());
    } catch (NumberFormatException nfe) {
        ParseException pe = new ParseException(
                "Error parsing integer value for " + directiveName + " directive", index);
        pe.initCause(nfe);
        throw pe;
    }
}
 
Example 4
Project: castor   File: DoubleToDate.java View source code 7 votes vote down vote up
/**
 * [email protected]}
 */
public Object convert(final Object object) {
    try {
        return getCustomDateFormat().parse(getDecimalFormat().format(object).trim());
    } catch (ParseException ex) {
        throw new IllegalArgumentException(ex.toString());
    }
}
 
Example 5
Project: geotools-old   File: Angle.java View source code 7 votes vote down vote up
/**
 * Constructs a newly allocated [email protected] Angle} object that represents the angle value
 * represented by the string. The string should represents an angle in either fractional
 * degrees (e.g. 45.5°) or degrees with minutes and seconds (e.g. 45°30').
 *
 * @param  string A string to be converted to an [email protected] Angle}.
 * @throws NumberFormatException if the string does not contain a parsable angle.
 */
public Angle(final String string) throws NumberFormatException {
    final Format format = getAngleFormat();
    final Angle theta;
    try {
        synchronized (Angle.class) {
            theta = (Angle) format.parseObject(string);
        }
    } catch (ParseException exception) {
        NumberFormatException e = new NumberFormatException(exception.getLocalizedMessage());
        e.initCause(exception);
        throw e;
    }
    if (getClass().isAssignableFrom(theta.getClass())) {
        this.theta = theta.theta;
    } else {
        throw new NumberFormatException(string);
    }
}
 
Example 6
Project: Time4J   File: XMLAdapter.java View source code 7 votes vote down vote up
@Override
public Duration<IsoUnit> translate(javax.xml.datatype.Duration source) {

    if (source.getSign() == 0) {
        return Duration.ofZero();
    }

    try {
        return Duration.parsePeriod(source.toString());
    } catch (ParseException ex) {
        if (ex.getCause() instanceof NumberFormatException) {
            ArithmeticException ae = new ArithmeticException();
            ae.initCause(ex);
            throw ae;
        }
        throw new ChronoException("Cannot translate: " + source, ex);
    }

}
 
Example 7
Project: ilarkesto   File: DateFormField.java View source code 6 votes vote down vote up
public void validate() throws ValidationException {
	if (value == null) {
		if (isRequired()) throw new ValidationException("Eingabe erforderlich");

	} else {
		try {
			Date.parseTolerant(value);
		} catch (ParseException ex) {
			throw new ValidationException("Eingabe muss ein Datum sein. " + ex.getMessage());
		}
	}
}