简体   繁体   English

无法找出丢失的返回语句错误

[英]can't figure out missing return statement error

I am actually trying to fit something like the following in my code which can be found in the link mentioned below the code: 我实际上正在尝试在我的代码中添加类似以下内容的代码,可以在代码下面提到的链接中找到该代码:

Statement stmt;
ResultSet rs;
boolean done = false;
int i = 0;
while(!done) {
    try {
        stmt = connections[i].createStatement();
        rs = stmt.executeQuery("select * from aTable");
        rs.beforeFirst();
        while(rs.next()) {
            // Do whatever you need with the result set
        }
        done = true;
    } catch(SQLException e) {
        // Catch the exception and try with the next connection
        i++;
    }
}

Link : https://ideone.com/as1XI8 链接: https : //ideone.com/as1XI8

So, I have added int i & boolean done variables on Line #83 & 84 Added while loop starting from line 91 and setting done = true in line 380 因此,我在第83和84行中添加了int iboolean done变量,并从第91行开始添加了while循环,并在第380行中设置了done = true

Finally, I am incrementing the variable i(i++) on line 389 and closing the while loop on line 463 with the brace. 最后,我在第389行增加变量i(i++) ,并用大括号关闭第463行的while循环。

After doing this, I am getting an error on line 80 ( starting brace just before int iterations = 0; ) in Netbeans saying that "missing return statement". 完成此操作后,我在Netbeans的第80行(在int iterations = 0;之前开始大括号)中收到一条错误,说"missing return statement".

I already have a return statement on line #460 and can't figure out why I am getting this error. 我已经在第460行上有一个return语句,无法弄清楚为什么会出现此错误。

Could anyone please download the code in your Netbeans/Eclipse and let me know what is wrong? 有人可以在您的Netbeans / Eclipse中下载代码,让我知道哪里出了问题吗?

Thanks !! 谢谢 !!

As your code format is far from practical, after the return statement in line 460, you have three closing brackets - one for the class, one for the method and one for the while loop, I assume - ensure, that there is a return statement at the end of the method every time, in your case, just move the return statement to the end of the method. 由于您的代码格式不太实用,因此在第460行的return语句之后,您有三个结束括号-我假设一个用于类,一个用于方法,一个用于while循环,请确保-确保有一个return语句。在您的情况下,每次在方法末尾,只需将return语句移到方法末尾即可。

Also, please learn how to format your code, this error has clearly been avoidable by correct formatting and indentation. 另外,请学习如何格式化代码,正确的格式化和缩进显然可以避免此错误。

You need to return after the while loop is done ! 您需要return after the while loop完成return after the while loop You are return inside the while loop ! 您将返回while循环!

Just take your return statement after one of the braces and see the magic 只需将大括号之一take your return statement中,然后看一下魔术

NOTE Please avoid putting down the whole code (escp. this type of messy code), it becomes a pain to go through it ! 注意请避免放下整个代码(尤其是这种杂乱的代码),这很麻烦! Take some time to format and make it human readable ! 请花一些时间格式化并使其human readable

Anyone can write codes that machine can read, its important to write codes that humans can read ! 任何人都可以编写机器可以读取的代码,这对于编写人类可以读取的代码很重要!

Your return statement is at wrong position. 您的退货单位置错误。 It is in the while loop. 它在while循环中。 write your return statement at line number 462 在第462行写您的退货声明

You need return statement for case when done is true and while loop won't even start. 您需要return语句,以确保done为true且while循环甚至不会启动。 Just add one more return with null or new ResultSet. 只需再添加一个具有null或新ResultSet的返回即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM