 <pre><code>java.lang.NoSuchMethodException: &lt;init&gt; [class android.content.Context, interface android.util.AttributeSet] </code></pre> <p>Your <code>HackySwipeBackLayout</code> is missing a constructor:</p> <pre><code>public HackySwipeBackLayout(Context context, AttributeSet attrs) { super(context, attrs); } </code></pre> <p>If you look more closely at the <a href="https://github.com/chrisbanes/PhotoView/blob/master/sample/src/main/java/uk/co/senab/photoview/sample/HackyViewPager.java" rel="nofollow"><code>HackyViewPager</code></a>, you'll notice that it is in there too. As a matter of fact, <em>any</em> view that needs to support inflating from xml should have this constructor defined. You may find the <a href="http://developer.android.com/intl/es/training/custom-views/create-view.html#subclassview" rel="nofollow">documentation on how to create custom views</a> helpful too.</p> <hr> <p>Edit: since your intention is to catch the exception thrown, make sure to catch the <code>ArrayIndexOutOfBoundsException</code> accordingly:</p> <pre><code>@Override public boolean onInterceptTouchEvent(MotionEvent ev) { try { return super.onInterceptTouchEvent(ev); } catch (ArrayIndexOutOfBoundsException e) { e.printStackTrace(); return false; } } </code></pre> <p>That should stop your app from crashing on this particular exception, but is of course not a 'fix' for the underlying issue that is causing the <code>ArrayIndexOutOfBoundsException</code> to be thrown in the first place. It may or may not lead to the desired behaviour. Either way, consider opening a <a href="https://github.com/liuguangqiang/SwipeBack/issues" rel="nofollow">ticket</a> with the maintainer of the SwipeBack repo.</p>