Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6951681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:15:03+00:00 2026-05-27T14:15:03+00:00

I am using viewpager with action-bar tab and I am have two fragment in

  • 0

I am using viewpager with action-bar tab and I am have two fragment in layout, and the problem is I am getting class-cast-exception

my xml file is look like below

 <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal" >

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

        <FrameLayout
            android:id="@+id/fragment_details"
            android:layout_width="0px"
            android:layout_height="match_parent"
            android:layout_weight="2" />
    </LinearLayout>

and I have two tabs in my activity songs and album.

It loads correctly in portrait mode but in, landscape mode it shows class cast exception.

12-08 04:30:08.198: E/AndroidRuntime(2166): FATAL EXCEPTION: main
12-08 04:30:08.198: E/AndroidRuntime(2166): java.lang.ClassCastException: com.nix.music.activity.fragments.SongDetailsFragment
12-08 04:30:08.198: E/AndroidRuntime(2166):     at com.nix.music.activity.fragments.AlbumFragMent.showDetails(AlbumFragMent.java:81)
12-08 04:30:08.198: E/AndroidRuntime(2166):     at com.nix.music.activity.fragments.AlbumFragMent.access$0(AlbumFragMent.java:77)
12-08 04:30:08.198: E/AndroidRuntime(2166):     at com.nix.music.activity.fragments.AlbumFragMent$1.onItemClick(AlbumFragMent.java:52)
12-08 04:30:08.198: E/AndroidRuntime(2166):     at android.widget.AdapterView.performItemClick(AdapterView.java:284)
12-08 04:30:08.198: E/AndroidRuntime(2166):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
12-08 04:30:08.198: E/AndroidRuntime(2166):     at android.os.Handler.handleCallback(Handler.java:587)
12-08 04:30:08.198: E/AndroidRuntime(2166):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-08 04:30:08.198: E/AndroidRuntime(2166):     at android.os.Looper.loop(Looper.java:123)
12-08 04:30:08.198: E/AndroidRuntime(2166):     at android.app.ActivityThread.main(ActivityThread.java:4627)
12-08 04:30:08.198: E/AndroidRuntime(2166):     at java.lang.reflect.Method.invokeNative(Native Method)
12-08 04:30:08.198: E/AndroidRuntime(2166):     at java.lang.reflect.Method.invoke(Method.java:521)
12-08 04:30:08.198: E/AndroidRuntime(2166):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-08 04:30:08.198: E/AndroidRuntime(2166):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-08 04:30:08.198: E/AndroidRuntime(2166):     at dalvik.system.NativeStart.main(Native Method)

error is shown in here

in AlbumFragMent class code for dual mode is

if (mDualPane) {
    AlbumDetailFragment details = (AlbumDetailFragment) getFragmentManager()
            .findFragmentById(R.id.fragment_details);
    if (details == null || details.getShownIndex() != index) {
        // Make new fragment to show this selection.
        details = AlbumDetailFragment.newInstance(index);

        // Execute a transaction, replacing any existing fragment
        // with this one inside the frame.
        FragmentTransaction ft = getFragmentManager()
                .beginTransaction();
        ft.replace(R.id.fragment_details, details);
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        ft.commit();

    }
}

and in SongFragment class

if (mDualPane) {
    getListView().setItemChecked(index, true);

    SongDetailsFragment details = (SongDetailsFragment) getFragmentManager()
            .findFragmentById(R.id.fragment_details);
    if (details == null || details.getShownIndex() != index) {
        // Make new fragment to show this selection.
        details = SongDetailsFragment.newInstance(index);

        // Execute a transaction, replacing any existing fragment
        // with this one inside the frame.
        FragmentTransaction ft = getFragmentManager()
                .beginTransaction();
        ft.replace(R.id.fragment_details, details);
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        ft.commit();
    }
}

only difference in both is the Detail fragment class which is calling.

Am I doing it wrong?

Is there anything else we need to take care of.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:15:04+00:00Added an answer on May 27, 2026 at 2:15 pm

    okay i solve this… the solution is kind of weird but works for me.

    I have decides to go with common detail-fragment class rather then having separate fragment class for each tab. and display the content based on the current current selection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem. I have a tabbed application implemented using a ViewPager.
I am using actionbarsherlock library to have action-bar in my application, I am also
I have a FragmentActivity using a ViewPager to serve several fragments. Each is a
I am using Android's support.v4 package to develop a ViewPager containing multiple Fragment s.
I have a project using a ViewPager which works correctly: I can page from
I am using ASP.NET MVC2 and have a problem. After Log off I manually
I have an app that uses ActionBarSherlock to provide a ViewPager control for tab
I have a late requirement change that requires tab navigation. I have already using
Basically I have two tabs. A Fragment and a ListFragment. When in the Fragment,
I have following problem: I have one activity in which I have two tabs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.