javaandroidpagerslidingtabstrip

Unable to start activity. Caused by: android.view.InflateException:


LogCat Error:
https://github.com/Heromine/tempapp1/issues/2

Can anybody tell me, why I am getting this error? I don't understand what i am doing wrong:

MainActivity.java:

       public class MainActivity extends ActionBarActivity {

    // UI elements
    public static Toolbar toolbar;
    public static ViewPager viewPager;
    private AppSectionsPagerAdapter mAppSectionsPagerAdapter;
    // Tab titles
    private String[] tabs = {"Home", "Note"};


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        SharedPreferences settings = getSharedPreferences("prefs", 0);
        boolean firstRun = settings.getBoolean("firstRun", true);
        if (firstRun) {  // here run your first-time instructions, for example :
            startActivity(new Intent(this, MyIntro.class));
            SharedPreferences.Editor editor = settings.edit();
            editor.putBoolean("firstRun", false);
            editor.commit();
        }

        mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

        // Set up the action/tool bar.
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar); // Setting toolbar with setSupportActionBar()

        // Initilization
        viewPager = (ViewPager) findViewById(R.id.pager);
        viewPager.setAdapter(mAppSectionsPagerAdapter);
      /*  ViewPager.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            swipeLayout.setEnabled(false);
            switch (event.getAction()) {
                case MotionEvent.ACTION_UP:
                    swipeLayout.setEnabled(true);
                    break;
            }
            return false;
        }
    });
    */

        // Adding Tabs
        PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
        tabs.setViewPager(viewPager);
        tabs.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                // When swiping between different app sections

                // change toolbar title
                if (position == 0)
                    toolbar.setTitle(getResources().getString(R.string.app_name));
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {

            case R.id.action_settings:
                startActivity(new Intent("android.intent.action.SettingsActivity"));
                return true;

            case R.id.action_donate:
                startActivity(new Intent("android.intent.action.DonateActivity"));
                return true;

            case R.id.action_rate:
                Intent i2 = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.service.beta.servicenotesbeta"));
                startActivity(i2);


                return super.onOptionsItemSelected(item);

            default:
                return super.onOptionsItemSelected(item);

        }


    }

    public static class AppSectionsPagerAdapter extends FragmentPagerAdapter {

        public AppSectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public android.support.v4.app.Fragment getItem(int i) {
            switch (i) {
                case 0:
                    return new Fragment_main();
                case 1:
                    return new Fragment_second();
            /*case 2:
                return new Fragment_third();
            case 3:
                return new Fragment_fourth();*/
                default:
                    return null;
            }
        }

        @Override
        public int getCount() {
            return 2; //3-4
        }

    }

}

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
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"
android:orientation="vertical">

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/ToolBarStyle"
    android:id="@+id/toolbar"/>

<com.astuetz.PagerSlidingTabStrip
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="48dip" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

 </RelativeLayout>

 </LinearLayout>

Please tell me what i am doing wrong I put the issue link because when i put the issue code it gives me an error


Solution

  • I fixed, the problem was that i didn't add the titles to the tabs