如何捕获由格式错误的layout-xml 文件引起的异常?

发布于 2024-09-25 13:27:50 字数 520 浏览 7 评论 0原文

    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?
    }
    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?
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

为人所爱 2024-10-02 13:27:50

你是认真的?这类事情不能只是“抓住”……它们必须得到解决。只需修复您的 XML 文件即可...捕获诸如 Exception 之类的内容是没有意义的;抓住它后你会做什么?

Are you serious? That kind of things cannot be just "catched"... they have to be fixed. Just fix your XML file and that's it... it does not make sense to catch such as Exception; what would you do after catching it?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文