Try catch 找不到符号ActionListener并尝试捕获
我的小程序有一个问题:简而言之,我想“获取”从xml中获取的变量curreny,并在单击“确定”按钮时打印它。我得到的错误是:错误:找不到符号curreny。问题不是从xml导入变量,因为我单独检查了它是否有效 对不起,代码太乱了,我是java新手。所有必需的包都是在原始源代码中导入的,但我把它放在这里并不是为了缩短代码。编辑:正如您所建议的,我删除了组成GUI的部分代码以使其更短Try catch 找不到符号ActionListener并尝试捕获,try-catch,actionlistener,Try Catch,Actionlistener,我的小程序有一个问题:简而言之,我想“获取”从xml中获取的变量curreny,并在单击“确定”按钮时打印它。我得到的错误是:错误:找不到符号curreny。问题不是从xml导入变量,因为我单独检查了它是否有效 对不起,代码太乱了,我是java新手。所有必需的包都是在原始源代码中导入的,但我把它放在这里并不是为了缩短代码。编辑:正如您所建议的,我删除了组成GUI的部分代码以使其更短 public class App2 extends Applet implements ActionListene
public class App2 extends Applet implements ActionListener {
TextField T1 = new TextField();
Label L1 = new Label();
/* GUI code here */
public void actionPerformed(ActionEvent ae)
{
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document xmlDocument = db.parse(new URL("http://www.nbp.pl/kursy/xml/LastA.xml").openStream());
xmlDocument.getDocumentElement().normalize();
XPath xPath = XPathFactory.newInstance().newXPath();
String expression = "/tabela_kursow/pozycja[3]/kurs_sredni";
// System.out.println(expression);
NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
for (int i = 0; i < nodeList.getLength(); i++) {
// System.out.println(nodeList.item(i).getFirstChild().getNodeValue());
String kurs_dolara = nodeList.item(i).getFirstChild().getNodeValue();
double d_kurs_dolara = Double.parseDouble(kurs_dolara.replace(',', '.'));
System.out.println(d_kurs_dolara*6);
}
expression = "/tabela_kursow/pozycja[8]/kurs_sredni";
nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
for (int i = 0; i < nodeList.getLength(); i++) {
String kurs_euro = nodeList.item(i).getFirstChild().getNodeValue();
double d_kurs_euro = Double.parseDouble(kurs_euro.replace(',', '.'));
System.out.println(d_kurs_euro*6);
}
expression = "/tabela_kursow/pozycja[11]/kurs_sredni";
nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
for (int i = 0; i < nodeList.getLength(); i++) {
String kurs_funta = nodeList.item(i).getFirstChild().getNodeValue();
double d_kurs_funta = Double.parseDouble(kurs_funta.replace(',', '.'));
System.out.println(d_kurs_funta*6);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (XPathExpressionException e) {
e.printStackTrace();
}
String wynik = String.valueOf(d_kurs_euro);
L1.setText(wynik);
repaint();
}}
public类App2扩展Applet实现ActionListener{
TextField T1=新的TextField();
标签L1=新标签();
/*这里的GUI代码*/
已执行的公共无效行动(行动事件ae)
{
试一试{
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=dbf.newDocumentBuilder();
Document xmlDocument=db.parse(新URL(“http://www.nbp.pl/kursy/xml/LastA.xmlopenStream());
xmlDocument.getDocumentElement().normalize();
XPath=XPathFactory.newInstance().newXPath();
字符串表达式=“/tabela_kursow/pozycja[3]/kurs_sredni”;
//System.out.println(表达式);
NodeList NodeList=(NodeList)xPath.compile(expression.evaluate(xmlDocument,XPathConstants.NODESET);
for(int i=0;i
孩子,我们要读的代码太多了!看看这个关于提问的页面:现在好了吗?我删除了GUI部分,它相当长。