Search code examples
androidandroid-asynctasksamsung-mobile

Android: App works on all devices except Samsung. How to solve? FATAL EXCEPTION: AsyncTask #2


The application I'm building at the moment works on all devices except the once from Samsung. And the error is Android version independent.

Here is my error report when running the app on an Samsung galaxy or a Samsung tab 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

Added the code in ErrorCodeList around line 167:

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"))) {
...

What could be the problem? My AsyncTask works perfectly on any other device. What is different on a samsung phone?


Solution

  • Ok guys I solved it. @Janusz a little bit of debugging did the trick. The problem was not in the XML structure nor in the fact that the error occurred on only Samsung devices. What happened was that my XML hyperlink listens to the language of the device and then gets the correct XML file. But during development I didn't had a certain language on the server yet happens to have the coincidence that all the Samsung devices I got from my colleagues had that particular language on them. doh! Never the less thanks for thinking with me!