0

I am using a custom view pager to disable swiping on certain tabs. The project builds without error but the app crashes with this error: java.lang.RuntimeException: Unable to start activity ComponentInfo{mypackage/mypackage.activity}: java.lang.ClassCastException: android.support.v4.view.ViewPager cannot be cast to mypackage.CustomViewPager

It seems to fail at this line of code:

mViewPager = (CustomViewPager) findViewById(R.id.pager1);

Here is the custom pager code:

public class CustomViewPager extends ViewPager {

//private boolean enabled;

public CustomViewPager(Context context) {
    super(context);
}

public CustomViewPager(Context context, AttributeSet attrs) {
    super(context, attrs);
}

@Override
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
    if (v instanceof WebView) {
        return true;
    }
    return super.canScroll(v, checkV, dx, x, y);
}

Here is the XML code also:

<mypackage.CustomViewPager 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pager1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

Any help would be greatly appreciated!

cstokes2
  • 105
  • 1
  • 2
  • 8

0 Answers0