1
更改我的應用程序的主軟件包名稱時出現奇怪的xml解析問題。在改變它以後,一切都出錯了,我發現從web解析的文本就像垃圾數據一樣。我已經檢查過從哪個RSS數據源解析數據,但它工作正常。而且我的共享偏好不工作,也有mysql數據庫的問題。我附上了截屏(其網格視圖顯示新聞標題)。請看看。我也附上代碼來解析XML。任何幫助將是提前appreciated..Thanks ...更改軟件包名稱時出現奇怪的解析問題
public static void parse() { //method to parse XML feeds
URL url;
try {
url = new URL(urls);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) {
DocumentBuilderFactory dbf = DocumentBuilderFactory
.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc;
doc = db.parse(url.openStream());
doc.getDocumentElement().normalize();
NodeList itemLst = doc.getElementsByTagName("item");
nl = doc.getElementsByTagName(KEY_HEAD);
Description = new String[itemLst.getLength()];// ........
Title = new String[itemLst.getLength()];
Tit = new String[itemLst.getLength()];
Tit2 = new String[itemLst.getLength()];
Desc = new String[itemLst.getLength()];
Desc2 = new String[itemLst.getLength()];
image = new String[itemLst.getLength()];
for (int i = 0; i < itemLst.getLength(); i++) {
Node item = itemLst.item(i);
if (item.getNodeType() == Node.ELEMENT_NODE) {
Element ielem = (Element) item;
NodeList title = ielem.getElementsByTagName("title");
NodeList date = ielem.getElementsByTagName("pubDate");
NodeList description = ielem
.getElementsByTagName("description");
Tit[i] = title.item(0).getChildNodes().item(0)
.getNodeValue();
Desc[i] = description.item(0).getChildNodes().item(0)
.getNodeValue();
Tit2[i] = Translate.title(Tit[i]);
Desc2[i] = Translate.description(Desc[i]);
if (Headlines.headflag == "malayalam") {
Desc2[i] = Desc2[i].replace("read more", "IqSpX�");
}
Title[i] = Tit2[i];
if (Desc2[i].contains("<img ")) {
String img = Desc2[i].substring(Desc2[i]
.indexOf("<img "));
String cleanUp = img.substring(0,
img.indexOf(">") + 1);
img = img.substring(img.indexOf("src=") + 5);
int indexOf = img.indexOf("'");
if (indexOf == -1) {
indexOf = img.indexOf("\"");
}
img = img.substring(0, indexOf);
// setImgLink(img);
if (Headlines.headflag == "malayalam") {
String img2 = img.replace("files",
"files/imagecache/android_320");
Description[i] = Desc2[i].replace(img, img2);
image[i] = img2;
}
else {
String img2 = img.replace("files",
"files/imagecache/android_1_img");
Description[i] = Desc2[i].replace(img, "");
image[i] = img2;
}
} else {
Description[i] = Desc2[i];
}
}
}
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DOMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
你怎麼改包的名字嗎?嘗試回滾你的項目,看看它是否可以再次運作 –
是的,當我回滾時它的工作正常。但它非常重要,我必須更改軟件包名稱......我首先將其從androidtools->重命名軟件包名稱更改。改變它後,我發現它在某些類中沒有改變。所以我重命名了根文件夾(com.app)也...之後,問題發生 –
好吧,聽起來不錯,嘗試在所有類中搜索您的舊包名 –