我的活動,在的onCreate()我嘗試獲取數據:catch異常
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
...............
fillUI();
}
public void getDetailedItem(){
FeedParser parser=new FeedParser();
try{
mItem=parser.parseDetailed();
}catch(Exception e){
closeAndShowError();
}
}
public void fillUI(){
getDetailedItem();
if(mItem!=null){
...............
}else{
closeAndShowError();
}
}
private void closeAndShowError(){
Context context = getApplicationContext();
CharSequence text = getResources().getString(R.string.toast_error);
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
finish();
}
他們的問題是,當異常occures,它被抓住了,我希望我的活動來完成本身,但我還是在fillUI()裏面執行代碼,所以我必須在getDetailedItem()後面加上if語句; 我該如何解決它?
你能捕捉到了異常詮釋他'fillUI()'方法? – spot35