-1

Look for class MyPagerActivity and MyFragment

There is the error coming Unable to locate GetResources(), and MyFragment's static is not allowed. The code was earlier running perfectly well, and suddenly these errors started showing, when I added the Floating Action Button classes. I am very new in Android Programming. Kindly Help.

    package demo.demo2;

import android.app.Activity;
import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import demo.demo2.FloatingActionButton;
import demo.demo2.FloatingActionsMenu;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

import tabs.SlidingTabLayout;

public class Main3Activity extends AppCompatActivity {
    private ViewPager mPager;
    private Toolbar toolbar;
    Activity activity;

    private SlidingTabLayout mTabs;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);

        Toolbar toolbar= (Toolbar) findViewById(R.id.app_bar);
        setSupportActionBar(toolbar);
       getSupportActionBar().setHomeButtonEnabled(true);
       getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        NavigationDrawerFragment drawerFragment=(NavigationDrawerFragment)getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);

        drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), toolbar);


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

        mPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
        mTabs = (SlidingTabLayout) findViewById(R.id.tabs);
    mTabs.setViewPager(mPager);

        findViewById(R.id.pink_icon).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(Main3Activity.this, "Clicked pink Floating Action Button", Toast.LENGTH_SHORT).show();
            }
        });






        FloatingActionButton button = (FloatingActionButton) findViewById(R.id.setter);
        button.setSize(FloatingActionButton.SIZE_MINI);
        button.setColorNormalResId(R.color.pink);
        button.setColorPressedResId(R.color.pink_pressed);
        button.setIcon(R.drawable.ic_fab_star);
        button.setStrokeVisible(false);

        final View actionB = findViewById(R.id.action_b);

        FloatingActionButton actionC = new FloatingActionButton(getBaseContext());
        actionC.setTitle("Hide/Show Action above");
        actionC.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                actionB.setVisibility(actionB.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
            }
        });

        final FloatingActionsMenu menuMultipleActions = (FloatingActionsMenu) findViewById(R.id.multiple_actions);
        menuMultipleActions.addButton(actionC);

        final FloatingActionButton removeAction = (FloatingActionButton) findViewById(R.id.button_remove);
        removeAction.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ((FloatingActionsMenu) findViewById(R.id.multiple_actions_down)).removeButton(removeAction);
            }
        });

        ShapeDrawable drawable = new ShapeDrawable(new OvalShape());
        drawable.getPaint().setColor(getResources().getColor(R.color.white));
        ((FloatingActionButton) findViewById(R.id.setter_drawable)).setIconDrawable(drawable);

        final FloatingActionButton actionA = (FloatingActionButton) findViewById(R.id.action_a);
        actionA.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                actionA.setTitle("Action A clicked");
            }
        });

        // Test that FAMs containing FABs with visibility GONE do not cause crashes
        findViewById(R.id.button_gone).setVisibility(View.GONE);

        final FloatingActionButton actionEnable = (FloatingActionButton) findViewById(R.id.action_enable);
        actionEnable.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                menuMultipleActions.setEnabled(!menuMultipleActions.isEnabled());
            }
        });

        FloatingActionsMenu rightLabels = (FloatingActionsMenu) findViewById(R.id.right_labels);
        FloatingActionButton addedOnce = new FloatingActionButton(this);
        addedOnce.setTitle("Added once");
        rightLabels.addButton(addedOnce);

        FloatingActionButton addedTwice = new FloatingActionButton(this);
        addedTwice.setTitle("Added twice");
        rightLabels.addButton(addedTwice);
        rightLabels.removeButton(addedTwice);
        rightLabels.addButton(addedTwice);
    }











    }


    class MyPagerAdapter extends FragmentPagerAdapter {
        String[] tabs;
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
            tabs =getResources().getStringArray(R.array.tabs);
        }

        @Override
        public Fragment getItem(int position) {
            MyFragment myFragment=MyFragment.getInstance(position);
            return myFragment;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return tabs[position];
        }

        @Override
        public int getCount() {
            return 6;
        }
    }

    public static class MyFragment extends Fragment {
        private TextView textView;
        public static MyFragment getInstance(int position) {

            MyFragment myFragment = new MyFragment();
            Bundle args=new Bundle();
            args.putInt("position",position);
            myFragment.setArguments(args);
            return myFragment;

        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View layout=inflater.inflate(R.layout.fragment_my,container,false);
            textView=(TextView)layout.findViewById(R.id.position);
            Bundle bundle=getArguments();
            if (bundle!=null)
            {
                textView.setText("The Page Selected is"  +bundle.getInt("position"));
            }
            return layout;
        }
    }

And this is the stack Trace

Executing tasks: [clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:compileDebugSources, :app:compileDebugAndroidTestSources]

Configuration on demand is an incubating feature. :clean UP-TO-DATE :app:clean :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72311Library :app:prepareComAndroidSupportCardviewV72311Library :app:prepareComAndroidSupportDesign2311Library :app:prepareComAndroidSupportRecyclerviewV72311Library :app:prepareComAndroidSupportSupportV42311Library :app:prepareComGetbaseFloatingactionbutton1101Library :app:prepareDebugDependencies :app:compileDebugAidl :app:compileDebugRenderscript :app:generateDebugBuildConfig :app:generateDebugAssets UP-TO-DATE :app:mergeDebugAssets :app:generateDebugResValues UP-TO-DATE :app:generateDebugResources :app:mergeDebugResources :app:processDebugManifest :app:processDebugResources :app:generateDebugSources :app:preDebugAndroidTestBuild UP-TO-DATE :app:prepareDebugAndroidTestDependencies :app:compileDebugAndroidTestAidl :app:processDebugAndroidTestManifest :app:compileDebugAndroidTestRenderscript :app:generateDebugAndroidTestBuildConfig :app:generateDebugAndroidTestAssets UP-TO-DATE :app:mergeDebugAndroidTestAssets :app:generateDebugAndroidTestResValues UP-TO-DATE :app:generateDebugAndroidTestResources :app:mergeDebugAndroidTestResources :app:processDebugAndroidTestResources :app:generateDebugAndroidTestSources :app:compileDebugJavaWithJavac C:\Users\acer\Desktop\Aprajeeta\Studies\android_work\Demo2\app\src\main\java\demo\demo2\Main3Activity.java:151: error: cannot find symbol tabs =getResources().getStringArray(R.array.tabs); ^ symbol: method getResources() location: class MyPagerAdapter Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. 1 error

FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'.

    Compilation failed; see the compiler error output for details.

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 39.934 secs

XML File

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

xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"

tools:context="demo.demo2.Main3Activity"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">

  <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout

        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/app_bar"
        android:orientation="vertical"
        tools:context="demo.demo2.Main3Activity">
        <include
            android:id="@+id/app_bar"
            layout="@layout/app_bar" />

        <tabs.SlidingTabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

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


        <demo.demo2.FloatingActionButton
            android:id="@+id/pink_icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            fab:fab_icon="@drawable/ic_fab_star"
            fab:fab_colorNormal="@color/pink"
            fab:fab_colorPressed="@color/pink_pressed"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="16dp"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@id/pink_icon"
            android:text="Text below button"
            android:layout_centerHorizontal="true"
            style="@style/menu_labels_style"
            android:layout_marginBottom="48dp"/>

        <demo.demo2.AddFloatingActionButton
            android:id="@+id/semi_transparent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@id/pink_icon"
            fab:fab_plusIconColor="@color/white"
            fab:fab_colorNormal="@color/blue_semi_transparent"
            fab:fab_colorPressed="@color/blue_semi_transparent_pressed"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="16dp"/>

        <demo.demo2.FloatingActionButton
            android:id="@+id/setter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@id/semi_transparent"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="16dp"/>

        <demo.demo2.AddFloatingActionButton
            android:id="@+id/normal_plus"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            fab:fab_plusIconColor="@color/half_black"
            fab:fab_colorNormal="@color/white"
            fab:fab_colorPressed="@color/white_pressed"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginStart="16dp"/>

        <demo.demo2.FloatingActionsMenu
            android:id="@+id/right_labels"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_above="@id/normal_plus"
            android:layout_marginLeft="16dp"
            android:layout_marginStart="16dp"
            fab:fab_addButtonColorNormal="@color/white"
            fab:fab_addButtonColorPressed="@color/white_pressed"
            fab:fab_addButtonPlusIconColor="@color/half_black"
            fab:fab_addButtonSize="mini"
            fab:fab_labelStyle="@style/menu_labels_style"
            fab:fab_labelsPosition="right">

            <demo.demo2.FloatingActionButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                fab:fab_colorNormal="@color/white"
                fab:fab_title="Label on the right"
                fab:fab_colorPressed="@color/white_pressed"/>

            <demo.demo2.FloatingActionButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                fab:fab_colorNormal="@color/white"
                fab:fab_size="mini"
                fab:fab_title="Another one on the right"
                fab:fab_colorPressed="@color/white_pressed"/>

        </demo.demo2.FloatingActionsMenu>

        <demo.demo2.FloatingActionsMenu
            android:id="@+id/multiple_actions"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            fab:fab_addButtonColorNormal="@color/white"
            fab:fab_addButtonColorPressed="@color/white_pressed"
            fab:fab_addButtonPlusIconColor="@color/half_black"
            fab:fab_labelStyle="@style/menu_labels_style"
            android:layout_marginBottom="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginEnd="16dp">

            <demo.demo2.FloatingActionButton
                android:id="@+id/action_a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                fab:fab_colorNormal="@color/white"
                fab:fab_title="Action A"
                fab:fab_colorPressed="@color/white_pressed"/>

            <demo.demo2.FloatingActionButton
                android:id="@+id/action_b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                fab:fab_colorNormal="@color/white"
                fab:fab_title="Action with a very long name that won\'t fit on the screen"
                fab:fab_colorPressed="@color/white_pressed"/>

        </demo.demo2.FloatingActionsMenu>

        <demo.demo2.FloatingActionsMenu
            android:id="@+id/multiple_actions_down"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentTop="true"
            fab:fab_addButtonColorNormal="@color/white"
            fab:fab_addButtonColorPressed="@color/white_pressed"
            fab:fab_addButtonSize="mini"
            fab:fab_addButtonPlusIconColor="@color/half_black"
            fab:fab_expandDirection="down"
            fab:fab_labelStyle="@style/menu_labels_style"
            android:layout_marginTop="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginEnd="16dp">

            <demo.demo2.FloatingActionButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                fab:fab_colorNormal="@color/white"
                fab:fab_colorPressed="@color/white_pressed"
                fab:fab_size="mini"/>

            <demo.demo2.FloatingActionButton
                android:id="@+id/button_remove"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                fab:fab_colorNormal="@color/white"
                fab:fab_colorPressed="@color/white_pressed"
                fab:fab_title="Click to remove"/>

            <demo.demo2.FloatingActionButton
                android:id="@+id/button_gone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                fab:fab_colorNormal="@color/white"
                fab:fab_colorPressed="@color/white_pressed"/>

            <demo.demo2.FloatingActionButton
                android:id="@+id/action_enable"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                fab:fab_colorNormal="@color/white"
                fab:fab_title="Set bottom menu enabled/disabled"
                fab:fab_colorPressed="@color/white_pressed"/>

        </demo.demo2.FloatingActionsMenu>

        <demo.demo2.FloatingActionsMenu
            android:id="@+id/multiple_actions_left"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@+id/multiple_actions_down"
            android:layout_toStartOf="@+id/multiple_actions_down"
            android:layout_alignParentTop="true"
            fab:fab_addButtonColorNormal="@color/white"
            fab:fab_addButtonColorPressed="@color/white_pressed"
            fab:fab_addButtonSize="mini"
            fab:fab_addButtonPlusIconColor="@color/half_black"
            fab:fab_addButtonStrokeVisible="false"
            fab:fab_expandDirection="left"
            android:layout_marginTop="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginEnd="16dp">

            <demo.demo2.FloatingActionButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                fab:fab_colorNormal="@color/white"
                fab:fab_colorPressed="@color/white_pressed"/>

            <demo.demo2.FloatingActionButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                fab:fab_colorNormal="@color/white"
                fab:fab_colorPressed="@color/white_pressed"
                fab:fab_size="mini"/>

            <demo.demo2.FloatingActionButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:visibility="gone"
                fab:fab_colorNormal="@color/white"
                fab:fab_colorPressed="@color/white_pressed"
                fab:fab_size="mini"/>

        </demo.demo2.FloatingActionsMenu>

        <demo.demo2.AddFloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/setter_drawable"
            android:layout_above="@id/setter"
            android:layout_centerHorizontal="true"/>


    </LinearLayout>
    <fragment
        android:id="@+id/fragment_navigation_drawer"
        android:layout_width="@dimen/nav_drawer_width"
        android:layout_height="match_parent"
        app:layout="@layout/fragment_navigation_drawer"
        android:layout_gravity="start"
        android:name="demo.demo2.NavigationDrawerFragment"
        tools:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>

1 Answers1

0

Error at following line

mTabs = (SlidingTabLayout) findViewById(R.id.tabs);

--- app:compileDebugJavaWithJavac C:\Users\acer\Desktop\Aprajeeta\Studies\android_work\Demo2\app\src\main\java\demo\demo2\Main3Activity.java:151: error: cannot find symbol tabs

Please check whether id "tabs" not available in your layout. or name is different

Rakesh
  • 756
  • 1
  • 9
  • 19
  • Problem with SlidingTabLayout with Action Bar Class. See this post, it will help http://stackoverflow.com/questions/26540078/use-tab-with-new-toolbar-appcompat-v7-21 – Rakesh Feb 12 '16 at 08:33
  • Thank You, but I am unable to find the fix. If you could tell me where exactly am I going wrong and tell me how to correct it – Aprajeeta Sinha Feb 12 '16 at 09:05
  • Will debug online tomorrow or today late evening, If it is OK will char and solve. – Rakesh Feb 12 '16 at 09:16