【发布时间】:2014-02-12 19:31:08
【问题描述】:
我有一个愚蠢的问题要问你们,因为我收到此代码的错误。
这是我在 Stackoverflow 上的第一篇文章,如有错误,请见谅。
我想通过这样说返回一个布尔值(真或假):
VerifyClassUnlocked.verify(account.email,account.password,"PRIEST");
在另一个班级。
package realmclient;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
public class VerifyClassUnlocked {
public static boolean verify(String EMAIL, String PASSWORD, String CLASS) {
URL url;
InputStream is = null;
BufferedReader br;
String line;
try {
url = new URL("https://realmofthemadgod.appspot.com/char/list?guid="+EMAIL+"&password="+PASSWORD);
is = url.openStream(); // throws an IOException
br = new BufferedReader(new InputStreamReader(is));
while ((line = br.readLine()) != null) {
System.out.println(line);
if (line.contains("<ClassAvailability id=\""+CLASS+"\">unrestricted</ClassAvailability>")){
return true;
}else{
return false;
}
}
} catch (MalformedURLException mue) {
mue.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
if (is != null) is.close();
} catch (IOException ioe) {
// nothing to see here
}
}
}
}
【问题讨论】:
-
你得到什么错误?这应该是您发布的第一件事和您搜索的第一件事。
-
请提及问题并发表具体问题。
-
感谢大家的快速回答。我的问题是: public static boolean verify(String EMAIL, String PASSWORD, String CLASS) { 不正确。它说“它必须返回一种布尔值”。
-
如果您的
while的条件在第一次运行时返回 false 会发生什么?你的方法应该返回什么?如果try内部抛出异常会怎样?
标签: java class url boolean return