查看setContentView源码可以看到,最终调用的是rInflate。
首先遍历所有的节点,假如是普通的view就直接获取,是Viewgroup的话会调用rInflateChildren,
发现在rInflateChildren里面调用的还是rInflate,是一个递归调用。
而且没有退出条件,就会导致不断地进行压栈。类似这种情况,JVM 实际会抛出 StackOverFlowError;当然,如果 JVM 试图去扩展栈空间的的时候失败,则会抛出 OutOfMemoryError。
栈最多存放多少栈帧取决于虚拟机设置的参数。
/**
* Recursive method used to inflate internal (non-root) children. This
* method calls through to {@link #rInflate} using the parent context as
* the inflation context.
* Note: Default visibility so the BridgeInflater can
* call it.
*/
final void rInflateChildren(XmlPullParser parser, View parent, AttributeSet attrs,
boolean finishInflate) throws XmlPullParserException, IOException {
rInflate(parser, parent, parent.getContext(), attrs, finishInflate);
}