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就好了。为什么呢,希望得到详细的解释。

解决方案 »

  1.   

    我如果去掉Try/catch将异常放到方法外边,为什么就可以了。
      

  2.   

    你把异常放到方法外面,那么你的语句str_d=new String(byte_b);
    就一定能执行到,那么就不存在str_d没有被赋值的可能,但是,像你上面
    的程序,当byte_b = str_S.getBytes("US-ASCII");语句在执行中出现异常
    后,程序会执行e.printStackTrace();
    ,然后再执行return str_d; 这时你的局部变量str_d没有赋值,所以报错。明白了吧?
      

  3.   

    就是说你上面的程序中存在str_d没有被赋值的可能。
      

  4.   

    HitXU(一天不学习,赶不上刘少奇) 说得很对
      

  5.   

    支持HitXU(一天不学习,赶不上刘少奇)