2012-09-17 74 views
0
@Override 
protected InputStream doInBackground(String... url){     
    try { 
     InputStream stream = downloadXml(url[0]); 
     new ParseXml(stream); //for testing porpuses: outputs ok to logcat 
     return stream; 
    } catch (IOException e) { 
     Log.d("dbg","exception"); 
     e.printStackTrace(); 
     return null; 
    } 
} 

@Override 
protected void onPostExecute(InputStream result) { 
    if (result != null) {  
     new ParseXml(result); //crashes the app     
    } 
    Log.d("dbg","postexecute triggered ok");   
} 

代码是非常自我解释我想,我试图改变传球类型,只是对象和类型铸造需要的地方,但它并没有任何工作。AsyncTask有什么问题吗?

有什么SDK中,我应该知道的无证?

+1

显示你的堆栈跟踪 – Yahor10

+0

http://pastebin.com/0Tadgs3P – FireFly

回答

1

显然,崩溃..你正在做冗长的(也可能是网络相关的)操作MainUI线程。作为onPostExecute()的AsyncTask运行在在短短MainUI主题。所以请始终保持在doInBackground()

该代码行new ParseXml(result);应该在doInBackground()AsyncTask

更新:

所以完成XML的解析中doInBackground()且仅当只有你想反映应用程序UI更新用传递结果onPostExecute()

+0

但我需要它在postexecute所以我返回可以使用MainUI的结果。 – FireFly

+0

看看我的更新答案.. – user370305

+0

去尝试感谢。 – FireFly