error: cannot find Symbol variable Toolbar and section_format

Asked

Viewed 285 times

0

I’m learning to code for Android and created an app from scratch on an empty screen. Then, I decided to put my Activity in a model with tabs, where the first tab would be this screen I already made and the second I would still program. I created a blank Activity with the tabs template and started copying the codes of this new Activity for my project. The problem is that now I’m stuck on two errors and can’t fix it. I’ve searched several places and nothing.

It’s probably something simple for you, but since I’m new, I can’t see the problem.

Error:(90, 37) error: cannot find Symbol variable Toolbar and Error:(523, 48) error: cannot find Symbol variable section_format

Mainactivity.java:

mtoolbar = findViewById(R.id.toolbar);
        setSupportActionBar(mtoolbar);
        // Create the adapter that will return a fragment for each of the three
        // primary sections of the activity.
        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
        mViewPager = (ViewPager) findViewById(R.id.container);
        mViewPager.setAdapter(mSectionsPagerAdapter);
        FloatingActionButton fab = findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

-

public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_tab, menu);
        return true;
    }
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    public void setSupportActionBar(Toolbar supportActionBar) {
        this.mtoolbar = supportActionBar; //        this.supportActionBar = supportActionBar;
    }

    public FragmentManager getSupportFragmentManager() {
        return supportFragmentManager;
    }

    public static class PlaceholderFragment extends Fragment {
        /**
         * The fragment argument representing the section number for this
         * fragment.
         */
        private static final String ARG_SECTION_NUMBER = "section_number";

        public PlaceholderFragment() {
        }

        /**
         * Returns a new instance of this fragment for the given section
         * number.
         */
        public static PlaceholderFragment newInstance(int sectionNumber) {
            PlaceholderFragment fragment = new PlaceholderFragment();
            Bundle args = new Bundle();
            args.putInt(ARG_SECTION_NUMBER, sectionNumber);
            fragment.setArguments(args);
            return fragment;
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.activity_main, container, false);
            TextView textView = (TextView) rootView.findViewById(R.id.section_label);
            textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
            return rootView;
        }
    }public class SectionsPagerAdapter extends FragmentPagerAdapter {

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

        @Override
        public Fragment getItem(int position) {
            // getItem is called to instantiate the fragment for the given page.
            // Return a PlaceholderFragment (defined as a static inner class below).
            return PlaceholderFragment.newInstance(position + 1);
        }

        @Override
        public int getCount() {
            // Show 3 total pages.
            return 3;
        }
    }

XML:

<android.support.constraint.ConstraintLayout
    android:id="@+id/constraintLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.mateuspc1.tab.TabActivity$PlaceholderFragment">

    <TextView
        android:id="@+id/section_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:layout_constraintLeft_toLeftOf="parent"
        ads:layout_constraintTop_toTopOf="@+id/constraintLayout"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintTop_creator="1" />

    <ScrollView
        android:id="@+id/ScrollView01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        ads:layout_constraintBottom_toTopOf="parent"
        ads:layout_constraintEnd_toEndOf="parent"
        ads:layout_constraintStart_toStartOf="parent"
        ads:layout_constraintTop_toTopOf="parent">

        <android.support.constraint.ConstraintLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <ImageButton
                android:id="@+id/vitasbut"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="@string/todo"
                android:src="@drawable/vitas1e2"
                ads:layout_constraintBottom_toTopOf="@+id/gtabut"
                ads:layout_constraintEnd_toStartOf="@+id/vitasbut2"
                ads:layout_constraintHorizontal_chainStyle="spread_inside"
                ads:layout_constraintStart_toStartOf="parent"
                ads:layout_constraintTop_toTopOf="parent" />

            <ImageButton
                android:id="@+id/vitasbut2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="@string/todo"
                android:src="@drawable/vitas2e2"
                ads:layout_constraintEnd_toStartOf="@+id/aiaichoquebut"
                ads:layout_constraintStart_toEndOf="@+id/vitasbut"
                ads:layout_constraintTop_toTopOf="parent" />

            <ImageButton
                android:id="@+id/gtabut"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="@string/todo"
                android:src="@drawable/gta1e2"
                ads:layout_constraintBottom_toTopOf="@+id/bolsbut"
                ads:layout_constraintEnd_toStartOf="@+id/gtabut2"
                ads:layout_constraintStart_toStartOf="parent"
                ads:layout_constraintTop_toBottomOf="@+id/vitasbut" />

            <ImageButton
                android:id="@+id/gtabut2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="@string/todo"
                android:src="@drawable/gta2e2"
                ads:layout_constraintEnd_toStartOf="@+id/acertomizbut"
                ads:layout_constraintStart_toEndOf="@+id/gtabut"
                ads:layout_constraintTop_toBottomOf="@+id/vitasbut2" />

            <ImageButton
                android:id="@+id/gabebut"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:contentDescription="@string/todo"
                android:src="@drawable/gabe1e2"
                ads:layout_constraintEnd_toEndOf="parent"
                ads:layout_constraintStart_toEndOf="@+id/gtabut2"
                ads:layout_constraintTop_toBottomOf="@+id/aiaichoquebut" />

            <ImageButton
                android:id="@+id/bolsbut"
                android:layout_width="0dp"
                android:layout_height="105dp"
                android:contentDescription="@string/todo"
                android:src="@drawable/bols1e2"
                ads:layout_constraintEnd_toStartOf="@+id/bolsbut2"
                ads:layout_constraintStart_toStartOf="parent"
                ads:layout_constraintTop_toBottomOf="@+id/gtabut" />

            <ImageButton
                android:id="@+id/bolsbut2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:contentDescription="@string/todo"
                android:src="@drawable/bols2e2"
                ads:layout_constraintEnd_toStartOf="@+id/aiaichoquebut"
                ads:layout_constraintStart_toEndOf="@+id/bolsbut"
                ads:layout_constraintTop_toBottomOf="@+id/gtabut2" />

            <ImageButton
                android:id="@+id/acertomizbut"
                android:layout_width="111dp"
                android:layout_height="0dp"
                android:src="@drawable/acertmiz1e2"
                ads:layout_constraintEnd_toEndOf="parent"
                ads:layout_constraintStart_toEndOf="@+id/bolsbut2"
                ads:layout_constraintTop_toBottomOf="@+id/gabebut" />

            <ImageButton
                android:id="@+id/aiaichoquebut"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/aiaichoque1e2"
                ads:layout_constraintBottom_toTopOf="@+id/gabebut"
                ads:layout_constraintEnd_toEndOf="parent"
                ads:layout_constraintStart_toEndOf="@+id/vitasbut2"
                ads:layout_constraintTop_toTopOf="parent" />

            <ImageButton
                android:id="@+id/bnsetimaartebut"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:src="@drawable/bnsetimaarte1e2"
                ads:layout_constraintStart_toStartOf="parent"
                ads:layout_constraintTop_toBottomOf="@+id/bolsbut" />

            <ImageButton
                android:id="@+id/fausteroubut"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/fausterou1e2"
                ads:layout_constraintStart_toEndOf="@+id/bnsetimaartebut"
                ads:layout_constraintTop_toBottomOf="@+id/onImageGalleryClicked" />

            <ImageButton
                android:id="@+id/fausttapegfogbut"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/faustfogo1e2"
                ads:layout_constraintStart_toStartOf="parent"
                ads:layout_constraintTop_toBottomOf="@+id/bnsetimaartebut" />

            <Button
                android:id="@+id/onImageGalleryClicked"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="24dp"
                android:layout_marginTop="24dp"
                android:onClick="onImageGalleryClicked"
                android:text="Button"
                ads:layout_constraintStart_toEndOf="@+id/bnsetimaartebut"
                ads:layout_constraintTop_toBottomOf="@+id/bolsbut2"
                android:layout_marginLeft="24dp" />

            <ImageView
                android:id="@+id/imgPicture"
                android:layout_width="53dp"
                android:layout_height="55dp"
                android:layout_marginStart="156dp"
                ads:layout_constraintStart_toEndOf="@+id/fausttapegfogbut"
                tools:layout_editor_absoluteY="389dp" />

        </android.support.constraint.ConstraintLayout>


    </ScrollView>

</android.support.constraint.ConstraintLayout>

<android.support.constraint.ConstraintLayout
    android:id="@+id/adViewConstraint"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    ads:layout_constraintEnd_toEndOf="parent"
    ads:layout_constraintStart_toStartOf="parent"
    app:layout_constraintBottom_toBottomOf="parent">

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="320dp"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        app:adSize="BANNER"
        app:adUnitId="ca-app-pub-3940256099942544/6300978111"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.656"
        app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>

  • In your strings.xml file, add this line: <string name="section_format">Tab de numero: %d</string>

  • Hi! Thanks for the help! section_format error solved. error: cannot find Symbol variable Toolbar still persists

  • This error is arising because it does not find a Toolbar in your activity_main.xml. You can post this layout on your question?

  • Hi! I found the error: I was missing android.support.v7.widget.Toolbar in my XML. Thanks for the help!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.