我正在尝试使用 web 服务(国家详细信息)制作 midlet。我不确定如何显示结果,其他一切似乎都很好。
这是获取输入信息和结果的代码(我无法获得):
task = new SimpleCancellableTask();
task.setExecutable(new org.netbeans.microedition.util.Executable() {
public void execute() throws Exception {
String country = FieldCountry.getString();
result = CWS.getCurrencyByCountry(country);
System.out.println(result);
getResultBox().setString(String.valueOf(result));
}
});
在运行窗口中,我看到它得到以下信息:
<NewDataSet>
<Table>
<Name>Norway</Name>
<CountryCode>no</CountryCode>
<Currency>Kroner</Currency>
<CurrencyCode>NOK</CurrencyCode>
</Table>
<Table>
<Name>Norway</Name>
<CountryCode>no</CountryCode>
<Currency>Kroner</Currency>
<CurrencyCode>NOK</CurrencyCode>
</Table>
</NewDataSet>
编辑
我已经使用了这段代码,现在它工作正常:
task = new SimpleCancellableTask();
task.setExecutable(new org.netbeans.microedition.util.Executable() {
public void execute() throws Exception {
country CWS = new country_Stub();
String country = FieldCountry.getString();
String result = CWS.getCurrencyByCountry(country);
if (list != null)
{list = null; }
String name = result.substring(result.indexOf("<Name>")+6, result.indexOf("</Name>"));
String countryc = result.substring(result.indexOf("<CountryCode>")+13, result.indexOf("</CountryCode>"));
String currency = result.substring(result.indexOf("<Currency>")+10, result.indexOf("</Currency>"));
String currencyc = result.substring(result.indexOf("<CurrencyCode>")+14, result.indexOf("</CurrencyCode>"));
getList().append("Country name: ", null);
getList().append(name, null);
getList().append("Country code: ", null);
getList().append(countryc, null);
getList().append("Country currency: ", null);
getList().append(currency, null);
getList().append("Country currency code: ", null);
getList().append(currencyc, null);
}
});