At work today, an unexpected exception was encountered:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/41/1F/wKiom1PQzc7xIN37AALO7_svFHI872.jpg "title=" Problem stack " alt= "Wkiom1pqzc7xin37aalo7_svfhi872.jpg"/>
The code for the problem is this (the contextual information has been removed):
LOG.I (Log_tag, New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss", Locale.china)
. Format (System.currenttimemillis ()));
Check repeatedly, feel no problem, then create a new Java Project, directly output the same code:
public class main{
public static void Main (string[] args) {
System.out.println (New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss", Locale.china)
. Format (System.currenttimemillis ()));
}
}
The resulting result is this:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/41/1F/wKiom1PQzw3z8mgdAADNqOEXNz0576.jpg "title=" Java Project "alt=" Wkiom1pqzw3z8mgdaadnqoexnz0576.jpg "/>
feel strange, then consult the Android API, in Java.text.SimpleDateFormat In the description table, unlike Java SE, in the description of "year", there is only "Y", there is no "y". When you replace "Y" in your code with lowercase, the problem is resolved.
This is the different pit of the API. I've seen some of them before, but today this is a bit of an accident that I haven't noticed before. Summary: If you have a strange problem with Java standard code in the future, it's a good idea to look at the Android API to make sure that your calls are correct and valid.
This article is from the "Flying Cat" blog, be sure to keep this source http://flyingcat2013.blog.51cto.com/7061638/1529773