如何捕获格式错误的layout-xml文件导致的异常?

时间:2010-09-29 13:42:38

标签: android exception-handling android-widget android-layout android-xml

    public class MyActivity extends Activity {

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            //R.layout.main has an illegal element (e.g. no layout_height attribute) 
            //But no exception is thrown at this line.
            setContentView(R.layout.main); 

        } //Exception will be thrown after this line. Where to catch it?
    }

1 个答案:

答案 0 :(得分:3)

你是认真的吗?这种事情不能只是“ catched ”......他们必须得到修复。只需修复你的XML文件,就是这样......捕获例如Exception是没有意义的;抓住后你会怎么做?