我有一个通过https-URL请求获取一些XML数据的方法。它从我的计算机上的Netbeans中以Java运行,但没有在Android上运行。它不会编译。
我收到此错误:const data = [
{email: '100@email.com', amount: '30', date: '2018-12'},
{email: '100@email.com', amount: '30', date: '2018-11'},
{email: '100@email.com', amount: '30', date: '2018-10'},
{email: '200@email.com', amount: 0, date: '2018-12'},
{email: '200@email.com', amount:'30', date: '2018-11'},
{email: '200@email.com', amount:'30', date: '2018-10'},
{email: '200@email.com', amount:'30', date: '2018-09'},
{email: '200@email.com', amount:'25', date: '2018-08'},
{email: '200@email.com', amount:'25', date: '2018-08'},]
let result = data.reduce((acc, {email, date, amount}) => {
if (!acc[email]) acc[email] = { email };
acc[email][date] = amount;
return acc;
}, {});
console.log(Object.values(result));
据我了解,所有抛出的异常都是必需的,否则我会遇到其他错误。
unreported exception ParserConfigurationException; must be caught or declared to be thrown
对这么多代码感到抱歉,但是我自己却无法解决。感谢您的任何帮助,谢谢!
答案 0 :(得分:0)
在调用方法的任何地方
try {
getWewtherMethod..
} catch (ParserConfigurationException || ParseException || SAXException ||IOException e) {
//handle exception
}
答案 1 :(得分:0)
您需要在调用getWeatherData
函数的地方处理异常。函数调用应如下所示。
try {
String[][] weatherData = getWeatherData();
} catch (ParserConfigurationException pce) {
System.out.println(pce.printStackTrace());
} catch (ParseException pe) {
System.out.println(pe.printStackTrace());
} catch (SAXException se) {
System.out.println(se.printStackTrace());
} catch (IOException ioe) {
System.out.println(ioe.printStackTrace());
} catch (Exception e) {
System.out.println(e.printStackTrace());
}
这个想法是要处理从该函数引发的异常。希望有帮助。