Android黄色警告汇总

1.

Warning:

// To get local formatting use getDateInstance(), getDateTimeInstance(), or

// getTimeInstance(), or use new SimpleDateFormat(String template, Locale

// locale) with for example Locale.US for ASCII dates.@SuppressLint("SimpleDateFormat")

String string = new SimpleDateFormat("EEEE  yyyy-MM-dd",Locale.getDefault()).format(new Date());

Solution:

添加Locale.getDefault()

for example,like:

SimpleDateFormat newSimpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日HH时mm分",Locale.getDefault());


2.Warning:

Implicitly using the default locale is a common source of bugs: Use toUpperCase(Locale) instead

String string = new SimpleDateFormat("EEEE",Locale.getDefault()).format(new Date()).toUpperCase();


Solution:

由于大写一般只应用在英语国家,所以Locale指定为Locale.US

String string = new SimpleDateFormat("EEEE",Locale.getDefault()).format(new Date()).toUpperCase(Locale.US);

(有时警告提示仍在,需要clean下才会消除)


未完待续......

你可能感兴趣的:(android,warning)