0

What i am doing:: I am trying to display a tabbed viewpager

MainActivity.java

public class MainActivity extends FragmentActivity implements TabListener  {

    ViewPager viewPager;
    ActionBar actionBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Set the view from main_fragment.xml

        requestWindowFeature(Window.FEATURE_ACTION_BAR);
        setContentView(R.layout.main_activity);

        viewPager=(ViewPager) findViewById(R.id.pager);

        viewPager.setAdapter(new MyAdapter(getSupportFragmentManager()));


        actionBar = getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        ActionBar.Tab tab1=actionBar.newTab();
        tab1.setText("Tab1");
        tab1.setTabListener(this);

        ActionBar.Tab tab2=actionBar.newTab();
        tab2.setText("Tab2");
        tab2.setTabListener(this);

        ActionBar.Tab tab3=actionBar.newTab();
        tab3.setText("Tab3");
        tab3.setTabListener(this);

        actionBar.addTab(tab1);
        actionBar.addTab(tab2);
        actionBar.addTab(tab3);

    }


    @Override
    protected void onDestroy() {
        Log.d(getClass().getName(), "[onDestroy(activity)]");
        super.onDestroy();
    }


    @Override
    public void onTabReselected(Tab arg0, android.app.FragmentTransaction arg1) {
        // TODO Auto-generated method stub

    }


    @Override
    public void onTabSelected(Tab arg0, android.app.FragmentTransaction arg1) {
        // TODO Auto-generated method stub

        viewPager.setCurrentItem(arg0.getPosition());
    }


    @Override
    public void onTabUnselected(Tab arg0, android.app.FragmentTransaction arg1) {
        // TODO Auto-generated method stub

    }

}


class MyAdapter extends FragmentPagerAdapter
{

    public MyAdapter(FragmentManager fm) {
        super(fm);
        // TODO Auto-generated constructor stub
    }

    @Override
    public Fragment getItem(int arg0) {
        // TODO Auto-generated method stub

        Fragment fragment=null;
        if(arg0==1){
            fragment=new SortRestaurantFragment();
        }
        if(arg0==2){
            fragment=new SortRestaurantFragment();

        }
        if(arg0==3){
            fragment=new SortRestaurantFragment();

        }
        return fragment;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return 3;
    }

}

main_activity.xml

<android.suppoort.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

I have also added the support libraries::

enter image description here enter image description here

Log::

02-10 02:34:17.471: E/AndroidRuntime(641): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.findmybuffet.restaurant_module/com.findmybuffet.restaurant_module.MainActivity}: android.view.InflateException: Binary XML file line #3: Error inflating class android.suppoort.v4.view.ViewPager
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.os.Looper.loop(Looper.java:137)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.app.ActivityThread.main(ActivityThread.java:4340)
02-10 02:34:17.471: E/AndroidRuntime(641):  at java.lang.reflect.Method.invokeNative(Native Method)
02-10 02:34:17.471: E/AndroidRuntime(641):  at java.lang.reflect.Method.invoke(Method.java:511)
02-10 02:34:17.471: E/AndroidRuntime(641):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-10 02:34:17.471: E/AndroidRuntime(641):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-10 02:34:17.471: E/AndroidRuntime(641):  at dalvik.system.NativeStart.main(Native Method)
02-10 02:34:17.471: E/AndroidRuntime(641): Caused by: android.view.InflateException: Binary XML file line #3: Error inflating class android.suppoort.v4.view.ViewPager
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-10 02:34:17.471: E/AndroidRuntime(641):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.app.Activity.setContentView(Activity.java:1835)
02-10 02:34:17.471: E/AndroidRuntime(641):  at com.findmybuffet.restaurant_module.MainActivity.onCreate(MainActivity.java:26)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.app.Activity.performCreate(Activity.java:4465)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
02-10 02:34:17.471: E/AndroidRuntime(641):  ... 11 more
02-10 02:34:17.471: E/AndroidRuntime(641): Caused by: java.lang.ClassNotFoundException: android.suppoort.v4.view.ViewPager
02-10 02:34:17.471: E/AndroidRuntime(641):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
02-10 02:34:17.471: E/AndroidRuntime(641):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
02-10 02:34:17.471: E/AndroidRuntime(641):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.view.LayoutInflater.createView(LayoutInflater.java:552)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
02-10 02:34:17.471: E/AndroidRuntime(641):  ... 20 more
02-10 02:34:17.471: E/AndroidRuntime(641): FATAL EXCEPTION: main
02-10 02:34:17.471: E/AndroidRuntime(641): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.findmybuffet.restaurant_module/com.findmybuffet.restaurant_module.MainActivity}: android.view.InflateException: Binary XML file line #3: Error inflating class android.suppoort.v4.view.ViewPager
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.os.Looper.loop(Looper.java:137)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.app.ActivityThread.main(ActivityThread.java:4340)
02-10 02:34:17.471: E/AndroidRuntime(641):  at java.lang.reflect.Method.invokeNative(Native Method)
02-10 02:34:17.471: E/AndroidRuntime(641):  at java.lang.reflect.Method.invoke(Method.java:511)
02-10 02:34:17.471: E/AndroidRuntime(641):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-10 02:34:17.471: E/AndroidRuntime(641):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-10 02:34:17.471: E/AndroidRuntime(641):  at dalvik.system.NativeStart.main(Native Method)
02-10 02:34:17.471: E/AndroidRuntime(641): Caused by: android.view.InflateException: Binary XML file line #3: Error inflating class android.suppoort.v4.view.ViewPager
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-10 02:34:17.471: E/AndroidRuntime(641):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.app.Activity.setContentView(Activity.java:1835)
02-10 02:34:17.471: E/AndroidRuntime(641):  at com.findmybuffet.restaurant_module.MainActivity.onCreate(MainActivity.java:26)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.app.Activity.performCreate(Activity.java:4465)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
02-10 02:34:17.471: E/AndroidRuntime(641):  ... 11 more
02-10 02:34:17.471: E/AndroidRuntime(641): Caused by: java.lang.ClassNotFoundException: android.suppoort.v4.view.ViewPager
02-10 02:34:17.471: E/AndroidRuntime(641):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
02-10 02:34:17.471: E/AndroidRuntime(641):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
02-10 02:34:17.471: E/AndroidRuntime(641):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.view.LayoutInflater.createView(LayoutInflater.java:552)
02-10 02:34:17.471: E/AndroidRuntime(641):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
02-10 02:34:17.471: E/AndroidRuntime(641):  ... 20 more

{Edit}

main_activity.xml

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

Log ::

02-10 03:02:09.681: E/AndroidRuntime(878): FATAL EXCEPTION: main
02-10 03:02:09.681: E/AndroidRuntime(878): java.lang.NullPointerException
02-10 03:02:09.681: E/AndroidRuntime(878):  at android.support.v4.app.BackStackRecord.doAddOp(BackStackRecord.java:394)
02-10 03:02:09.681: E/AndroidRuntime(878):  at android.support.v4.app.BackStackRecord.add(BackStackRecord.java:389)
02-10 03:02:09.681: E/AndroidRuntime(878):  at android.support.v4.app.FragmentPagerAdapter.instantiateItem(FragmentPagerAdapter.java:99)
02-10 03:02:09.681: E/AndroidRuntime(878):  at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:832)
02-10 03:02:09.681: E/AndroidRuntime(878):  at android.support.v4.view.ViewPager.populate(ViewPager.java:982)
02-10 03:02:09.681: E/AndroidRuntime(878):  at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
02-10 03:02:09.681: E/AndroidRuntime(878):  at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
02-10 03:02:09.681: E/AndroidRuntime(878):  at android.view.View.measure(View.java:12603)
02-10 03:02:09.681: E/AndroidRuntime(878):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4677)
02-10 03:02:09.681: E/AndroidRuntime(878):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
02-10 03:02:09.681: E/AndroidRuntime(878):  at android.view.View.measure(View.java:12603)
02-10 03:02:09.681: E/AndroidRuntime(878):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:812)
02-10 03:02:09.681: E/AndroidRuntime(878):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
02-10 03:02:09.681: E/AndroidRuntime(878):  at android.view.View.measure(View.java:12603)
02-10 03:02:09.681: E/AndroidRuntime(878):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4677)
02-10 03:02:09.681: E/AndroidRuntime(878):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
02-10 03:02:09.681: E/AndroidRuntime(878):  at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2072)
02-10 03:02:09.681: E/AndroidRuntime(878):  at android.view.View.measure(View.java:12603)
02-10 03:02:09.681: E/AndroidRuntime(878):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1044)
02-10 03:02:09.681: E/AndroidRuntime(878):  at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2418)
02-10 03:02:09.681: E/AndroidRuntime(878):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-10 03:02:09.681: E/AndroidRuntime(878):  at android.os.Looper.loop(Looper.java:137)
02-10 03:02:09.681: E/AndroidRuntime(878):  at android.app.ActivityThread.main(ActivityThread.java:4340)
02-10 03:02:09.681: E/AndroidRuntime(878):  at java.lang.reflect.Method.invokeNative(Native Method)
02-10 03:02:09.681: E/AndroidRuntime(878):  at java.lang.reflect.Method.invoke(Method.java:511)
02-10 03:02:09.681: E/AndroidRuntime(878):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-10 03:02:09.681: E/AndroidRuntime(878):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-10 03:02:09.681: E/AndroidRuntime(878):  at dalvik.system.NativeStart.main(Native Method)
2
  • How have you added android-support-v4.jar to your project? Commented Feb 9, 2014 at 21:14
  • @CommonsWare .... Mark Murphy Please see the edit ... i have posted a stack trace after edit Commented Feb 9, 2014 at 21:36

1 Answer 1

8

In your main_activity.xml, you have the class name spelled wrong.

android.suppoort.v4.view.ViewPager

should be

android.support.v4.view.ViewPager
Sign up to request clarification or add additional context in comments.

4 Comments

[+1] for pointing the typo but(i didnt notice that error even though im looking it for an hour ) ........ Still i have the same error ... even after making changes
You might want to post the new stack trace, since it's probably a different problem now.
@ ginovva320 ...... Yes ... its pointing a different error .... Please see the edit ...
I resolved the final error:: by changing get count returning value to 1 since i was returning one fragment for all the tabs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.