一個向量函數的返回:獲得一個矢量元素崩潰
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