J
Jacky
Hi,
I can't seemed to return a value and using the try/catch in
combination.
Main Program
-> Calls another program to open a file and returns the data as a
string
OpenFileMenu
-> Try
-> Open file
-> Append to string
-> Catch
-> Return
But it will mentioned it doesn't reconigse the return variable, it's
declared within the try and catch.
If I were to move the Return statement to within the try/catch, it
will prompt no return statement.
================================================================
--------------------Configuration: <Default>--------------------
C:\Documents and Settings\user\Desktop\Project\src\Project.java:86:
cannot resolve symbol
symbol : variable ret_value
location: class Project
return ret_value;
^
Note: C:\Documents and Settings\user\Desktop\Project\src\Project.java
uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
1 error
================================================================
public static void main(String[] args) throws Exception {
String file = OpenFileMenu();
}
static String OpenFileMenu() {
try {
//opening file
FileInputStream fstream = new FileInputStream(filename);
//converting input stream to DataInputStream
DataInputStream in = new DataInputStream(fstream);
StringBuffer bigBuf = new StringBuffer();
// reading file
while (in.available() != 0)
bigBuf = bigBuf.append(in.readLine());
String ret_value = bigBuf.toString();
//closing file
in.close();
}
catch (Exception e) {
System.err.println("File input error");
}
return ret_value;
}
================================================================
I can't seemed to return a value and using the try/catch in
combination.
Main Program
-> Calls another program to open a file and returns the data as a
string
OpenFileMenu
-> Try
-> Open file
-> Append to string
-> Catch
-> Return
But it will mentioned it doesn't reconigse the return variable, it's
declared within the try and catch.
If I were to move the Return statement to within the try/catch, it
will prompt no return statement.
================================================================
--------------------Configuration: <Default>--------------------
C:\Documents and Settings\user\Desktop\Project\src\Project.java:86:
cannot resolve symbol
symbol : variable ret_value
location: class Project
return ret_value;
^
Note: C:\Documents and Settings\user\Desktop\Project\src\Project.java
uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
1 error
================================================================
public static void main(String[] args) throws Exception {
String file = OpenFileMenu();
}
static String OpenFileMenu() {
try {
//opening file
FileInputStream fstream = new FileInputStream(filename);
//converting input stream to DataInputStream
DataInputStream in = new DataInputStream(fstream);
StringBuffer bigBuf = new StringBuffer();
// reading file
while (in.available() != 0)
bigBuf = bigBuf.append(in.readLine());
String ret_value = bigBuf.toString();
//closing file
in.close();
}
catch (Exception e) {
System.err.println("File input error");
}
return ret_value;
}
================================================================