gpt4 book ai didi

java - try catch 意外 token

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:22:53 24 4
gpt4 key购买 nike

此代码在 try and catch 中给出了意外 token 错误。怎么了?

public class WeatherTest
{

String weatherurl = "http://weather.yahooapis.com/forecastrss?w=35801&u=c";
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(weatherurl);

try {

HttpEntity httpEntity = httpClient.execute(httpGet).getEntity();

InputStream inputStream = httpEntity.getContent();
Reader in = new InputStreamReader(inputStream);
BufferedReader bufferedreader = new BufferedReader(in);
StringBuilder stringBuilder = new StringBuilder();

String stringReadLine = null;

while ((stringReadLine = bufferedreader.readLine()) != null)
{
stringBuilder.append(stringReadLine + "\n");
}

String qResult = stringBuilder.toString();

}
catch (IOException ie)
{
ie.printStackTrace();
}
}

最佳答案

您的 try/catch block 不在方法内。

你可以把它放在一个方法中,然后调用这个方法。

public class WeatherTest {
String weatherurl = "http://weather.yahooapis.com/forecastrss?w=35801&u=c";
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(weatherurl);

public void myMethod() {
try { ... }
catch { ... }
}
}

关于java - try catch 意外 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16616615/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com