Your instantiateItem() returns a ViewPager container container instead of the element that should be inside the container.
This is a special muck inflate() , which probably bit many before: if you call inflate(R.layout.createnew, container) , it returns a container like:
Returns
The root view of an overestimated hierarchy. If root has been set, this is root View ; otherwise, this is the root of the inflated XML file.
(selection is partly mine)
You do not get access to the actual root of the inflated hierarchy, only to the container with the new child view already attached.
In this case, addView() will actually be redundant because the new view is already in the container. However, in your code, it adds the container to itself. Android does not check the loops in the view hierarchy, but at some point you get an endless traversal loop (raising a StackOverflowError ).
Since instanceItem() needs to return a (child) view , this is a bit of a problem:
Gets an object representing the new page. This should not be a View, but it could be another page container.
To prevent a new view from being added to the container, change the call to
View view = inflate(R.layout.createnew, container, false) ;
and leave the addView() call as is. Now it is necessary, since the adapter should add a view to the container :
The adapter is responsible for adding the view to the container specified here, [...]