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

  • Home
  • SEARCH
  • 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 8425517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:17:32+00:00 2026-06-10T04:17:32+00:00

I’ve been trying to get 2 fragments work with a ViewPager with no success..

  • 0

I’ve been trying to get 2 fragments work with a ViewPager with no success.. Here is the Main FragmentActivity which contains the ViewPager:

public class DownloadCenter extends android.support.v4.app.FragmentActivity {
    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.download_center);
        ViewPager vp = (ViewPager) findViewById(R.id.DownloadCenter_viewPager);
        vp.setAdapter(new myAdapter(getSupportFragmentManager()));



    }

    public class myAdapter extends FragmentPagerAdapter {
        public myAdapter(FragmentManager fm) {
            super(fm);
        }

        Fragment[] fragmentArray = { Fragment.instantiate(DownloadCenter.this, Download_ImageQuality.class.getName()),
                Fragment.instantiate(DownloadCenter.this, Download_Tilawat.class.getName()) };

        @Override
        public Fragment getItem(int arg0) {
            return fragmentArray[arg0];
        }

        @Override
        public int getCount() {
            return fragmentArray.length;
        }


    }
}

Here is the logcat:

08-24 18:42:34.238: E/AndroidRuntime(4205): FATAL EXCEPTION: main
08-24 18:42:34.238: E/AndroidRuntime(4205): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.test/test.test.DownloadCenter}: java.lang.ClassCastException: test.test.Download_ImageQuality cannot be cast to android.support.v4.app.Fragment
08-24 18:42:34.238: E/AndroidRuntime(4205):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2079)
08-24 18:42:34.238: E/AndroidRuntime(4205):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
08-24 18:42:34.238: E/AndroidRuntime(4205):     at android.app.ActivityThread.access$600(ActivityThread.java:132)
08-24 18:42:34.238: E/AndroidRuntime(4205):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
08-24 18:42:34.238: E/AndroidRuntime(4205):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-24 18:42:34.238: E/AndroidRuntime(4205):     at android.os.Looper.loop(Looper.java:137)
08-24 18:42:34.238: E/AndroidRuntime(4205):     at android.app.ActivityThread.main(ActivityThread.java:4575)
08-24 18:42:34.238: E/AndroidRuntime(4205):     at java.lang.reflect.Method.invokeNative(Native Method)
08-24 18:42:34.238: E/AndroidRuntime(4205):     at java.lang.reflect.Method.invoke(Method.java:511)
08-24 18:42:34.238: E/AndroidRuntime(4205):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-24 18:42:34.238: E/AndroidRuntime(4205):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-24 18:42:34.238: E/AndroidRuntime(4205):     at dalvik.system.NativeStart.main(Native Method)
08-24 18:42:34.238: E/AndroidRuntime(4205): Caused by: java.lang.ClassCastException: test.test.Download_ImageQuality cannot be cast to android.support.v4.app.Fragment
08-24 18:42:34.238: E/AndroidRuntime(4205):     at android.support.v4.app.Fragment.instantiate(Fragment.java:388)
08-24 18:42:34.238: E/AndroidRuntime(4205):     at android.support.v4.app.Fragment.instantiate(Fragment.java:363)
08-24 18:42:34.238: E/AndroidRuntime(4205):     at test.test.DownloadCenter$myAdapter.<init>(DownloadCenter.java:29)
08-24 18:42:34.238: E/AndroidRuntime(4205):     at test.test.DownloadCenter.onCreate(DownloadCenter.java:18)
08-24 18:42:34.238: E/AndroidRuntime(4205):     at android.app.Activity.performCreate(Activity.java:4465)
08-24 18:42:34.238: E/AndroidRuntime(4205):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-24 18:42:34.238: E/AndroidRuntime(4205):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033)
08-24 18:42:34.238: E/AndroidRuntime(4205):     ... 11 more

Download_ImageQuality header:

public class Download_ImageQuality extends android.support.v4.app.FragmentActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.download_imagequality);
                 .... //REST OF CLASS
        }
}
  • 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-06-10T04:17:33+00:00Added an answer on June 10, 2026 at 4:17 am

    We can read from the documentation the following:

    ViewPager is most often used in conjunction with Fragment, which is a
    convenient way to supply and manage the lifecycle of each page. There
    are standard adapters implemented for using fragments with the
    ViewPager, which cover the most common use cases. These are
    FragmentPagerAdapter, FragmentStatePagerAdapter, FragmentPagerAdapter,
    and FragmentStatePagerAdapter; each of these classes have simple code
    showing how to build a full user interface with them.

    As you can see it talks about Fragments not FragmentActivities, the main difference between both of them is that a Fragment are the one that goes inside a FragmentActivity. You can think of them as:

    FragmentActivity = Activity

    Fragment = View

    NOTE: Is not exactly as this, this is just an approximation for make it clearer.

    So the best for you in this case is to use a FragmentPagerAdapter and make all the content of your ViewPager a Fragment, and the you can handle the full life cycle inside each page.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to select an H1 element which is the second-child in its group
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words

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.