public String getString(String str_S)
{
byte[] byte_b;
String str_d;
try {
byte_b = str_S.getBytes("US-ASCII");
str_d=new String(byte_b);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return str_d;
}
提示错误:The local variable str_d may not have been initialized改为:String str_d=null就好了。为什么呢,希望得到详细的解释。
{
byte[] byte_b;
String str_d;
try {
byte_b = str_S.getBytes("US-ASCII");
str_d=new String(byte_b);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return str_d;
}
提示错误:The local variable str_d may not have been initialized改为:String str_d=null就好了。为什么呢,希望得到详细的解释。
就一定能执行到,那么就不存在str_d没有被赋值的可能,但是,像你上面
的程序,当byte_b = str_S.getBytes("US-ASCII");语句在执行中出现异常
后,程序会执行e.printStackTrace();
,然后再执行return str_d; 这时你的局部变量str_d没有赋值,所以报错。明白了吧?