I am new to android development and seem to be stuck at the moment. Whenever I compile and test my app on a device I getting a fatal error message:
=1: thread exiting with uncaught exception (group=0x4137d930)
12-10 22:07:28.423: E/AndroidRuntime(20961): FATAL EXCEPTION: main
12-10 22:07:28.423: E/AndroidRuntime(20961): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hyperlocal.tradeit/com.hyperlocal.tradeit.MainActivity}: java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.support.v4.view.ViewPager
then app stops running after the splash screen.
The action bar doesn’t even appear in the graphical layout any more and the IDE cannot find any errors :/
Any help would be appreciated, thanks!
You have given the RelativeLayout an id of
android:id="@+id/pager"and in your code, you are trying to access it thinking it’s a ViewPager. These classes are not the same. In your RelativeLayout, you have to manually add a ViewPager and give thatandroid:id="@+id/pager.The Android Documentation does a good job of providing a template.
Here is what your code should resemble.