Friday, February 14, 2014

Scores help: Android multi-language issues [time]



Have not done too much buddy locale, help!

 
String pattern = "yyyy-MM-dd HH: mm: ss";


Now I'm in a Chinese environment, the constructor SimpleDateFormat incoming parameter pattern is valid.

But the switch to the English language, the prompt parameter pattern Invaild.

Log follows:
 
11-06 16:19:22.339: E / AndroidRuntime (2476): FATAL EXCEPTION: main
11-06 16:19:22.339: E / AndroidRuntime (2476): java.lang.ExceptionInInitializerError
11-06 16:19:22.339: E / AndroidRuntime (2476): at com.medzone.mcloud.bean.helper.RoleInfoHelper.getDefaultAvatar (RoleInfoHelper.java: 51)
11-06 16:19:22.339: E / AndroidRuntime (2476): at com.medzone.mcloud.ui.MainPage.fillView (MainPage.java: 148)
11-06 16:19:22.339: E / AndroidRuntime (2476): at com.medzone.mcloud.ui.MainPage.initUI (MainPage.java: 69)
11-06 16:19:22.339: E / AndroidRuntime (2476): at com.medzone.mcloud.ui.MainPage.onCreate (MainPage.java: 51)
11-06 16:19:22.339: E / AndroidRuntime (2476): at android.app.Activity.performCreate (Activity.java: 4471)
11-06 16:19:22.339: E / AndroidRuntime (2476): at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java: 1049)
11-06 16:19:22.339: E / AndroidRuntime (2476): at android.app.ActivityThread.performLaunchActivity (ActivityThread.java: 1933)
11-06 16:19:22.339: E / AndroidRuntime (2476): at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java: 1994)
11-06 16:19:22.339: E / AndroidRuntime (2476): at android.app.ActivityThread.access $ 600 (ActivityThread.java: 126)
11-06 16:19:22.339: E / AndroidRuntime (2476): at android.app.ActivityThread $ H.handleMessage (ActivityThread.java: 1150)
11-06 16:19:22.339: E / AndroidRuntime (2476): at android.os.Handler.dispatchMessage (Handler.java: 99)
11-06 16:19:22.339: E / AndroidRuntime (2476): at android.os.Looper.loop (Looper.java: 137)
11-06 16:19:22.339: E / AndroidRuntime (2476): at android.app.ActivityThread.main (ActivityThread.java: 4439)
11-06 16:19:22.339: E / AndroidRuntime (2476): at java.lang.reflect.Method.invokeNative (Native Method)
11-06 16:19:22.339: E / AndroidRuntime (2476): at java.lang.reflect.Method.invoke (Method.java: 511)
11-06 16:19:22.339: E / AndroidRuntime (2476): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java: 787)
11-06 16:19:22.339: E / AndroidRuntime (2476): at com.android.internal.os.ZygoteInit.main (ZygoteInit.java: 554)
11-06 16:19:22.339: E / AndroidRuntime (2476): at dalvik.system.NativeStart.main (Native Method)
11-06 16:19:22.339: E / AndroidRuntime (2476): Caused by: java.lang.IllegalArgumentException: Unknown pattern character 'o'
11-06 16:19:22.339: E / AndroidRuntime (2476): at java.text.SimpleDateFormat.validateFormat (SimpleDateFormat.java: 268)
11-06 16:19:22.339: E / AndroidRuntime (2476): at java.text.SimpleDateFormat.validatePattern (SimpleDateFormat.java: 309)
11-06 16:19:22.339: E / AndroidRuntime (2476): at java.text.SimpleDateFormat . (SimpleDateFormat.java: 369)
11-06 16:19:22.339: E / AndroidRuntime (2476): at java.text.SimpleDateFormat . (SimpleDateFormat.java: 253)
11-06 16:19:22.339: E / AndroidRuntime (2476): at com.medzone.mcloud.util.TimeUtil . (TimeUtil.java: 52)
11-06 16:19:22.339: E / AndroidRuntime (2476): ... 18 more



I found a little, very little information in this regard Chinese and English. . . You know. . . Help you!<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Caused by: java.lang.IllegalArgumentException: Unknown pattern character 'o'


Carefully check the string inside the "o"
Reply:
cited a floor l417584711 reply:
Caused by: java.lang.IllegalArgumentException: Unknown pattern character 'o'


Carefully check the string inside the "o"


Thanks in advance for your reply, in fact, you can see the Pattern and did not 'o'
Reply:
new SimpleDateFormat (pattern, Locale.ENGLISH); Try this way
Reply:
TimeUtil.java: 52 This line of code is valid
Reply:
reference to the third floor tantahe reply:
new SimpleDateFormat (pattern, Locale.ENGLISH); Try this way



references, 4th Floor l417584711 reply:
TimeUtil.java: 52 This line of code is valid


Thank you, buddy first reply, the problem I found;

I first posted some code in question, in case others search to this post, then no solution ~ hey
 
@ SuppressLint ("SimpleDateFormat")
public class TimeUtil {
private static Context context = GlobalVars.applicationContext;
private static final String TODAY = context.getResources (). getString (
R.string.today);
private static final String YESTERDAY = context.getResources (). getString (
R.string.yesterday);
private static final String HOURSAGO = context.getResources (). getString (
R.string.hoursAgo);
private static final String MINUTESAGO = context.getResources (). getString (
R.string.minutesAgo);
private static final String DAYSAGO = context.getResources (). getString (
R.string.daysAgo);
private static final String JUSTNOW = context.getResources (). getString (
R.string.justNow);
private static final String YEAR = context.getResources (). getString (
R.string.year);
private static final String MONTH = context.getResources (). getString (
R.string.month);
private static final String DAY = context.getResources (). getString (
R.string.day);
private static final SimpleDateFormat dateTimeFormat = new SimpleDateFormat (
"Yyyy-MM-dd HH: mm");
private static final SimpleDateFormat dateFormatAccurateToSecond = new SimpleDateFormat (
"Yyyy-MM-dd HH: mm: ss", Locale.getDefault ());
private static final SimpleDateFormat dateFormat = new SimpleDateFormat (
"Yyyy-MM-dd");
private static final SimpleDateFormat timeFormat1 = new SimpleDateFormat (
"HH: mm");

private static final SimpleDateFormat timeFormat2 = new SimpleDateFormat (
"HH: mm: ss");

private static final SimpleDateFormat timeFormat3 = new SimpleDateFormat (
"Yyyy");

private static final SimpleDateFormat timeFormatFriendly = new SimpleDateFormat (
"MM" + MONTH + "dd" + DAY + "HH: mm");


Question is the last one:
 
private static final SimpleDateFormat timeFormatFriendly = new SimpleDateFormat (
"MM" + MONTH + "dd" + DAY + "HH: mm");


There are Chinese parsing format is not supported; since English is the common, but in a different time zone, can have their own different time formats;
For example, here is Chinese, zn in the Chinese environment, little things do not;
However, the next ring en or other dry environment, it is a direct force close;
Sad reminder;

No comments:

Post a Comment