如何捕获由格式错误的layout-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?
}
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是认真的?这类事情不能只是“抓住”……它们必须得到解决。只需修复您的 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?