Rav
Rav

Reputation: 141

Action bar has disappeared

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 :/

Here is my code

Any help would be appreciated, thanks!

Upvotes: 2

Views: 118

Answers (1)

A--C
A--C

Reputation: 36449

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 that android:id="@+id/pager.

The Android Documentation does a good job of providing a template.

Here is what your code should resemble.

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:background="@drawable/bg" >


<android.support.v4.view.ViewPager 
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</RelativeLayout>

Upvotes: 4

Related Questions