Name: Anonymous 2012-12-08 17:34
Here's one of my classes:
For some reason, time.substring states that "The local variable time may not have been initialized", and it definitely has something to do with the scope in the try/catch. the issue is, I've declared time outside of the try/catch, and I have no idea how to fix this, because it looks like it should work.
Any help?
Thanks.
public static int secondOfDay() {
SimpleDateFormat timeUTC = new SimpleDateFormat("HH:mm:ss");
timeUTC.setTimeZone(TimeZone.getTimeZone("GMT"));
SimpleDateFormat dateFormatLocal = new SimpleDateFormat("HH:mm:ss");
String time;
int second;
try {
time = dateFormatLocal.parse(timeUTC.format(new Date())).toString().substring(11, 19).trim();
} catch (ParseException e) {
}
second = Integer.parseInt(time.substring(0,2)) * 3600 + Integer.parseInt(time.substring(3,5)) * 60 + Integer.parseInt(time.substring(6,8));
return second;
}For some reason, time.substring states that "The local variable time may not have been initialized", and it definitely has something to do with the scope in the try/catch. the issue is, I've declared time outside of the try/catch, and I have no idea how to fix this, because it looks like it should work.
Any help?
Thanks.