一个向量函数的返回:获得一个矢量元素崩溃
public Vector<Config> getConfigVector(){
XmlResourceParser xml = context.getResources().getXml(R.xml.configs);
Vector<Config> data = new Vector<Config>();
int eventType;
try {
eventType = xml.getEventType();
String[] attr = {"",""};
while (eventType != XmlPullParser.END_DOCUMENT) {
if(eventType == XmlPullParser.START_TAG) {
if(xml.getName().equals("config")){
Config item = new Config(xml.getAttributeValue(0),xml.getAttributeValue(1));
data.add(item);
}
}
eventType = xml.next();
}
} catch (Exception e) {
e.printStackTrace();
}
finally{
return data;
}
}
然后我想回路的元素:
String url = "", num = "", lang = "";
ConfigDb confdb = new ConfigDb(getApplicationContext());
Vector<Config> configs = confdb.getConfigVector();
int nb = configs.size();
for (int i=0; i<nb; i++) {
Config cfg = (Config)configs.get(i); // this causes bug which stopped the app
if (cfg.getConfigId() == "cfg.url") {
url = cfg.getConfigValue();
}
else if (cfg.getConfigId() == "cfg.number") {
num = cfg.getConfigValue();
}
else if (cfg.getConfigId() == "cfg.lang") {
lang = cfg.getConfigValue();
}
}
如何正确获取向量中的每个元素在这种情况下, ?
你会得到什么错误?为什么使用Vector而不是ArrayList? –
Logcat是空白的!好吧,我会尝试与ArrayList – pheromix
与arraylist相同的问题! – pheromix