1

以下のコードの JXpath 式の何が問題になっていますか? 次のコードは、常にこの例外をスローします。

org.apache.commons.jxpath.JXPathNotFoundException: No value for xpath: countries[gdp=4]

しかし、私は国ドイツが返されることを期待していました. ここで何が問題なのですか?

import org.apache.commons.jxpath.JXPathContext;

public class Test {

    private final Country[] countries = {
        new Country("US", 20),
        new Country("China", 13),
        new Country("Japan", 5),
        new Country("Germany", 4),
        new Country("UK", 3)};

    public static void main(String[] args) {
        Object result = JXPathContext.newContext(new Test()).getValue("countries[gdp=4]");
        System.out.println(result);
    }

    public Country[] getCountries() {
        return countries;
    }   
}

-

class Country{

    private String name;
    private int gdp;

    public Country(String name, Integer gdp){
        this.name=name;
        this.gdp=gdp;
    }

    @Override
    public String toString() {
        return name;
    }

    public String getName() {
        return name;
    }

    public int getGdp() {
        return gdp;
    }
}
4

2 に答える 2