找不到符号ActionListener并尝试catch

时间:2014-01-21 00:55:36

标签: try-catch actionlistener

我的applet有问题:简而言之,我想“获取”从xml中获取的变量curreny并在我点击按钮OK时将其打印出来。我得到的错误是:错误:找不到符号curreny。问题不是从xml导入变量,因为我单独检查它是否有效。

对于乱码我很抱歉,我是java的新手。所有必要的软件包都是在原始资源中导入的,但我并没有把它放在这里只是为了缩短代码。编辑:我删除了部分包含GUI的代码,使其缩短,如你所知。

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();
 }}

0 个答案:

没有答案