cancel
Showing results for 
Search instead for 
Did you mean: 

Java Error : This method must return a result of type JCO.Table

Former Member
0 Kudos

Hi all

I am new to Java !!!

Here is the piece of code that raises the error:

// Method to establish the Link for Outside World

public JCO.Table getLogonClientList() {

try {

myFunction = getFunctionModule();

myConnection.execute(myFunction);

myTable = myFunction.getTableParameterList().getTable("CLIENT_LIST");

return myTable;

}

catch (Exception e4) {

System.out.println(e4.toString());

}

}

When i try to compile the program, i am facing following error:

<b>Error This method must return a result of type JCO.Table</b>

I have already declared myTable(like others such as myConnection, myFunction) as JCO.Table in the beginning of the Class..

Any help please !!!

Thanks

Kay

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Kay,

This error is thrown because...

1. For a Successfull Scenario, i.e, if it works without causing any exception then it will return myTable.

2. But what if it causes any exception in the middle.

It will not return myTable. Right.

3. <b>Solution:</b> Add a finally block and return the myTable inside the finally block.

Check this link...

http://www.artima.com/underthehood/finally.html

Hope it helps.

Regards,

Maheswaran.B

Former Member
0 Kudos

Maheswaran

Among the other methods in the Class, this is the only method by which i am planning to execute the Functionality of the Class...

Does Finally will Work for the situation ???

Thanks

Kay

Message was edited by: Kay

Former Member
0 Kudos

Hi Kay,

The use of the finally block is that even if the exception is raised the finally block will get executed.

i.e Immaterial of what ever happens finally, finally block will get executed. If you want some set of statements to be run even if a exception is raised you can include that inside the finally block.

For an example,

You can close the connection in the finally block.

Finally Block is along with try catch syntax where finally block is optional.

For eg.

try{
}

catch(Exception e){
}

finally{
}

So, the functionality will work fine.

Alternative Solution:

Usually in java, the statements which causes exception are included in the try block.

In your case the return statement is not going to cause any exception. Right. So you can remove the return statement from the try block and include it just before the ending brace of your function. This will also work fine.

public JCO.Table getLogonClientList() {
try {
myFunction = getFunctionModule();
myConnection.execute(myFunction);
myTable = myFunction.getTableParameterList().getTable("CLIENT_LIST");
<b>//return myTable;</b> 
}
catch (Exception e4) {
System.out.println(e4.toString());
}
<b>return myTable;</b>
}

Hope it helps. Sorry for the delay.

Regards,

Maheswaran.B

Message was edited by: Maheswaran B

Former Member
0 Kudos

Maheswaran

Thanks for your support !!!

Finally worked !!!

Thanks

Kay

Answers (0)