我目前正在构建的应用程序适用于除三星设备之外的所有设备。并且该错误与 Android 版本无关。
这是我在三星 Galaxy 或三星标签 10.1 上运行应用程序时的错误报告:
11-02 10:04:49.748: I/System.out(11183): Wrong XML file structure: Unexpected token (position:TEXT File does not ex...@1:20 in java.io.StringReader@418eb450)
11-02 10:04:49.748: W/dalvikvm(11183): threadid=15: thread exiting with uncaught exception (group=0x40c511f8)
11-02 10:04:49.763: E/AndroidRuntime(11183): FATAL EXCEPTION: AsyncTask #2
11-02 10:04:49.763: E/AndroidRuntime(11183): java.lang.RuntimeException: An error occured while executing doInBackground()
11-02 10:04:49.763: E/AndroidRuntime(11183): at android.os.AsyncTask$3.done(AsyncTask.java:278)
11-02 10:04:49.763: E/AndroidRuntime(11183): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
11-02 10:04:49.763: E/AndroidRuntime(11183): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
11-02 10:04:49.763: E/AndroidRuntime(11183): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
11-02 10:04:49.763: E/AndroidRuntime(11183): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-02 10:04:49.763: E/AndroidRuntime(11183): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
11-02 10:04:49.763: E/AndroidRuntime(11183): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
11-02 10:04:49.763: E/AndroidRuntime(11183): at java.lang.Thread.run(Thread.java:856)
11-02 10:04:49.763: E/AndroidRuntime(11183): Caused by: java.lang.NullPointerException
11-02 10:04:49.763: E/AndroidRuntime(11183): at com.lgsvcacademy.lgrepairsupport.ErrorCodeList$GetDataTask.doInBackground(ErrorCodeList.java:167)
11-02 10:04:49.763: E/AndroidRuntime(11183): at com.lgsvcacademy.lgrepairsupport.ErrorCodeList$GetDataTask.doInBackground(ErrorCodeList.java:1)
11-02 10:04:49.763: E/AndroidRuntime(11183): at android.os.AsyncTask$2.call(AsyncTask.java:264)
11-02 10:04:49.763: E/AndroidRuntime(11183): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-02 10:04:49.763: E/AndroidRuntime(11183): ... 4 more
在第 167 行附近的 ErrorCodeList 中添加了代码:
String feedURL="...";
String xml = XMLfunctions.getXML(feedURL);
Document doc = XMLfunctions.XMLfromString(xml);
int numResults = 1;
if((numResults <= 0)){
Toast.makeText(ErrorCodeList.this, "No results found", Toast.LENGTH_LONG).show();
finish();
}
/*Line 167>*/ NodeList troubles = doc.getElementsByTagName("trouble");
for (int i = 0; i < troubles.getLength(); i++) {
String troubleTypeAtt;
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element)troubles.item(i);
troubleTypeAtt = e.getAttributes().getNamedItem("type").getNodeValue();
if((troubleTypeAtt.equals("error")) || (troubleTypeAtt.equals("notification"))) {
...
可能是什么问题呢?我的 AsyncTask 在任何其他设备上都能完美运行。三星手机有什么不同?