久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

XML 解析器返回意外的令牌錯誤和空指針異常

XML Parser Returning unexpected token error and null pointer exception(XML 解析器返回意外的令牌錯誤和空指針異常)
本文介紹了XML 解析器返回意外的令牌錯誤和空指針異常的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

所以我認為我在以前的帖子中質疑了錯誤的方式.我最好這樣說.我正在嘗試解析 XML 數據:

So I think I was questioning the wrong way in previous threads. I better put it like this. I'm trying to parse the XML data:

<playlist>
<title>![CDATA[New Playlist]]</title>
<items>
<item>
<title>HAMD(LA ILAHA ILLALLAH)</title>
<description>Recited By :Alhaaj Muhammad Owais Raza Qadri -- Written By: Mufti-e-Azam Hind Molana Mustafa Raza Khan Noori</description>
<image>http://xxx.xxx.xxx.xxx/~kanz/video/Images/9.jpg</image>
<startFromThis>true</startFromThis>
<duration>510</duration>
<source>http://xxx.xxx.xxx.xxx/~kanz/video/flv/9.flv</source>
<sourceAlt>http://xxx.xxx.xxx.xxx/~kanz/video/mp4/9.mp4</sourceAlt>
<sourceType>direct</sourceType>
</item>
</items>
</playlist>

在我的活動中,我所做的是這樣,但 logcat 給出了空指針異常.這是我的活動,下面是 logcat 錯誤.

In my Activity, what I did was this but the logcat gives null pointer exception. Here's my Activity and below it the logcat error.

static final String URL = "http://xxx.xxx.xxx.xxx/~kanz/video/XML/9.xml";

// XML node keyse.
static final String KEY_SONG = "item"; // parent node
static final String KEY_TITLE = "title";
static final String KEY_ARTIST = "description";
static final String KEY_THUMB_URL = "image";
static final String KEY_DURATION = "duration";

NodeList nl = doc.getElementsByTagName(KEY_SONG);

// looping through all song nodes <song>
for (int i = 0; i < nl.getLength(); i++) {
    // creating new HashMap
    HashMap<String, String> map = new HashMap <String, String>();
    Element e = (Element) nl.item(i);
    // adding each child node to HashMap key => value
    map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
    map.put(KEY_ARTIST, parser.getValue(e, KEY_ARTIST));
    map.put(KEY_THUMB_URL, parser.getValue(e, KEY_THUMB_URL));
    map.put(KEY_DURATION, parser.getValue(e, KEY_DURATION));

    // adding HashList to ArrayList
    songsList.add(map);
}

Logcat 給出 Unexpected Token 錯誤并返回 null 導致空指針異常.

Logcat gives Unexpected Token error and returns null which causes null pointer exception.

03-28 14:31:34.059: E/Error:(895): Unexpected token (position:TEXT ???@1:4 in java.io.StringReader@40d220e0) 
03-28 14:31:34.080: I/System.out(895): null
03-28 14:42:59.560: D/AndroidRuntime(978): Shutting down VM
03-28 14:42:59.560: W/dalvikvm(978): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
03-28 14:42:59.639: E/AndroidRuntime(978): FATAL EXCEPTION: main
03-28 14:42:59.639: E/AndroidRuntime(978): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.razatubevidurl/com.example.razatubevidurl.CustomizedListView}: java.lang.NullPointerException
03-28 14:42:59.639: E/AndroidRuntime(978):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-28 14:42:59.639: E/AndroidRuntime(978):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-28 14:42:59.639: E/AndroidRuntime(978):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-28 14:42:59.639: E/AndroidRuntime(978):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-28 14:42:59.639: E/AndroidRuntime(978):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-28 14:42:59.639: E/AndroidRuntime(978):  at android.os.Looper.loop(Looper.java:137)
03-28 14:42:59.639: E/AndroidRuntime(978):  at android.app.ActivityThread.main(ActivityThread.java:5041)
03-28 14:42:59.639: E/AndroidRuntime(978):  at java.lang.reflect.Method.invokeNative(Native Method)
03-28 14:42:59.639: E/AndroidRuntime(978):  at java.lang.reflect.Method.invoke(Method.java:511)
03-28 14:42:59.639: E/AndroidRuntime(978):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-28 14:42:59.639: E/AndroidRuntime(978):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-28 14:42:59.639: E/AndroidRuntime(978):  at dalvik.system.NativeStart.main(Native Method)
03-28 14:42:59.639: E/AndroidRuntime(978): Caused by: java.lang.NullPointerException

請告訴我我做錯了什么.我認為我之前的問題含糊不清,在這一個問題中,我盡力使問題清晰易懂.

Please tell me what I'm doing wrong. I thought my previous question was vague and in this one, I tried my best to make the question clear and understandable.

推薦答案

我猜這和編碼有關.也許您的解析器不喜歡感嘆號 (!).您能否確保使用正確編碼的 XML 文件?(UTF-8)

I guess it's something about encoding. Maybe your parser doesn't like the exclamation mark (!). Can you make sure that you use the XML file with the correct encoding? (UTF-8)

否則,你有這個問題:KXmlParser 拋出意外的令牌";RSS 開始時的異常.

Otherwise, you have this problem: KXmlParser throws "Unexpected token" exception at the start of RSS pasing.

我搜索了一下,看起來最簡單的解決方法是 這里.您可以嘗試添加此方法.(根據您使用的教程,將其放在 ImageLoader 類中.)

I googled around and it looks like the easiest fix is here. You can try adding this method. (From the tutorial you use, put this in the ImageLoader class.)

import java.io.PushbackInputStream;
private InputStream checkForUtf8BOMAndDiscardIfAny(InputStream inputStream) throws IOException {
PushbackInputStream pushbackInputStream = new PushbackInputStream(new BufferedInputStream(inputStream), 3);
byte[] bom = new byte[3];
if (pushbackInputStream.read(bom) != -1) {
    if (!(bom[0] == (byte) 0xEF && bom[1] == (byte) 0xBB && bom[2] == (byte) 0xBF)) {
        pushbackInputStream.unread(bom);
    }
}
return pushbackInputStream; }

那你就可以了

InputStream is=conn.getInputStream();
is = checkForUtf8BOMAndDiscardIfAny(is);

我沒有機會測試該方法,但它應該這樣做.另外,請參閱 字節順序標記搞砸了 Java 中的文件讀取.

I don't have a chance to test the method but it should do it. Also, please see Byte order mark screws up file reading in Java.

這篇關于XML 解析器返回意外的令牌錯誤和空指針異常的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Upload progress listener not fired (Google drive API)(上傳進度偵聽器未觸發(Google 驅動器 API))
Save file in specific folder with Google Drive SDK(使用 Google Drive SDK 將文件保存在特定文件夾中)
Google Drive Android API - Invalid DriveId and Null ResourceId(Google Drive Android API - 無效的 DriveId 和 Null ResourceId)
Google drive api services account view uploaded files to google drive using java(谷歌驅動api服務賬戶查看上傳文件到谷歌驅動使用java)
Google Drive service account returns 403 usageLimits(Google Drive 服務帳號返回 403 usageLimits)
com.google.api.client.json.jackson.JacksonFactory; missing in Google Drive example(com.google.api.client.json.jackson.JacksonFactory;Google Drive 示例中缺少)
主站蜘蛛池模板: 国产一二三视频在线观看 | 欧美在线观看黄色 | 国产免费观看久久黄av片涩av | 午夜精品久久 | 精品少妇v888av | 欧美久久一级特黄毛片 | 日韩二 | 欧美在线一区二区三区 | 国产精品日日做人人爱 | 国产成人啪免费观看软件 | 精品1区2区| 99re视频| 中文字幕高清 | 九九精品影院 | 国产视频一二三区 | 黄色大片视频 | 午夜在线电影网 | 成人精品国产免费网站 | 亚洲国产成人精品女人久久久 | 成年视频在线观看福利资源 | 欧美 日韩 国产 在线 | 黄色a级一级片 | 91人人看| 中文字幕亚洲国产 | 亚洲欧美一区在线 | www.色综合| 国产一区欧美 | 精品欧美在线观看 | 免费精品 | 欧美一区二区三区在线 | 中文字幕第一页在线 | 成人欧美一区二区三区黑人孕妇 | 久久天天躁狠狠躁夜夜躁2014 | 久久黄色网 | 日本精品视频一区二区 | 欧美一区2区三区3区公司 | 免费三级黄 | 久久久爽爽爽美女图片 | 欧美一区二区三区精品 | 欧美亚洲国产精品 | 久久www免费视频 |