English 中文(简体)
失踪回归声明[封闭]
原标题:Missing Return Statement [closed]
  • 时间:2011-07-13 07:43:46
  •  标签:
  • java

我正在阅读一个Excel文档,使用并找到我另一个人的起首位置。

这是我的法典。

public static int CheckStartPosition(String filename,int Colno,String StartChar, int sheetno,int startpos) { 
 try {

 Workbook workbook = new Workbook();

 workbook.open(filename);

 Worksheet worksheet = workbook.getWorksheets().getSheet(sheetno);

 Cells cells=worksheet.getCells();

 int num=cells.getMaxDataRow();

 int num1=cells.getMaxDataColumn();

 int numofsheet= workbook.getNumberOfSheets();

 System.out.println(numofsheet);

 for (int n1=0;n1<=num;n1++) {  
     Cell cell1=cells.getCell(n1,Colno);
     if(cell1.getValue()!=null) {

         String value =cell1.getValue().toString().toLowerCase();
         if(value.equals(StartChar)) {

         System.out.println( cell1.getValue());

         int S= cell1.getRowIndex();

         startpos=S+1;

         System.out.println(startpos);
         iii
     iiielse{iii
 iii 
 workbook.save("C:\Movies.xls",FileFormatType.EXCEL97TO2003);

 return startpos; 
 iii catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
 iii

iii

:-  

CheckStartPosition(f1.xls, 0,"abc",2,0);

www.un.org/Depts/DGACM/index_spanish.htm 如何返回起点

最佳回答

由于格式化,很难阅读。 检查站必须返回。 在你身上,你没有回过任何东西。 回返。 或者更确切地说,通过扔 throw海道和从《安全法》中捕获的鱼 drop来宣布《安全基本法》。 替代办法使用自己的例外类型。

问题回答

You are catching an exception, but not returning anything. Try this:

    catch (IOException e)
    {
        e.printStackTrace();
        return -1; // Some special value that means "I exploded"
    }

或者更好,不捕获和宣布你的方法throws IOException

You don t return anything is you get an exception. It is likely a better approach is to declare the actual exceptions in the throws clause of the method.

你们可以做的是,在你的试捕组面前宣布回归价值,并给予它一。 在你的试捕组中,你分配了价值。 在试捕区之后,你返回。

int CheckStartPosition(...)
{
   int returnInt = -1;
   try{
       ...
       returnInt = startpos; // instead of return startpos
       ...
    }catch(...){
        ...
        returnInt = -1; // if your code can crash after the "returnInt = startpos;"
    }
    return returnInt;
}

你必须用以下方法来形容你:

int returnedValue = CheckStartPosition(f1.xls, 0,"abc",2,0);




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签