简体   繁体   中英

ParseException only on Galaxy Nexus

I tested my app on 5 various phones and this exception occurs only on Samsung Galaxy Nexus:

java.text.ParseException: Unparseable date: "Sun, 19 Feb 2012 14:02:43 +0100" (at offset 0)

My input string:

<pubDate>Sun, 19 Feb 2012 14:02:43 +0100</pubDate>

My code:

private String getString(Element item, String tag) {

    Element e = (Element) item.getElementsByTagName(tag).item(0);
    return e.getFirstChild().getNodeValue();
}

SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss ZZZZ");
String tmpDate = getString(item, "pubDate");
Date pubDate = new Date(System.currentTimeMillis());
pubDate = sdf.parse(tmpDate);

Is this a problem of Android 4.0 or I made some mistake?

In addition I have a problem with my national signs. I have xml in UTF-8, and I want to display it in WebView. I have UTF-8 encoded html file and it works perfect on all devices except Galaxy Nexus - it display some strange characters instead of my national signs.

Do you have any ideas?

I would bet that the Nexus has a different locale set by default. Try using the

SimpleDateFormat(String pattern, Locale locale) 

variant of the constructor to explicitly set the locale you expect in your date string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM