android.support.v7.internal.widget.ActionBarOverlayLayout could not be instantiated

AndroidAndroid Studio

Android Problem Overview


I installed (Android studio 1.2 + SDK pack) for the first time, I created a test project with demo tab activity. I have not written a single line of code, everything has been generated by Android Studio

In fragment_main.xml the following problem occurs.

enter image description here

java.lang.ClassNotFoundException: android.support.v4.view.ViewPropertyAnimatorListener
	at org.jetbrains.android.uipreview.ModuleClassLoader.load(ModuleClassLoader.java:127)
	at com.android.tools.idea.rendering.RenderClassLoader.findClass(RenderClassLoader.java:53)
	at org.jetbrains.android.uipreview.ModuleClassLoader.findClass(ModuleClassLoader.java:84)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
	at java.lang.Class.getDeclaredConstructors0(Native Method)
	at java.lang.Class.privateGetDeclaredConstructors(Class.java:2585)
	at java.lang.Class.getConstructor0(Class.java:2885)
	at java.lang.Class.getConstructor(Class.java:1723)
	at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:348)
	at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:105)
	at com.android.tools.idea.rendering.LayoutlibCallback.loadView(LayoutlibCallback.java:177)
	at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:214)
	at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:142)
	at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
	at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
	at com.android.layoutlib.bridge.bars.BridgeActionBar.<init>(BridgeActionBar.java:84)
	at com.android.layoutlib.bridge.bars.AppCompatActionBar.<init>(AppCompatActionBar.java:56)
	at com.android.layoutlib.bridge.impl.RenderSessionImpl.createActionBar(RenderSessionImpl.java:1691)
	at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:362)
	at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:321)
	at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
	at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:497)
	at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:485)
	at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:894)
	at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:485)
	at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:590)
	at com.intellij.android.designer.designSurface.AndroidDesignerEditorPanel$6.run(AndroidDesignerEditorPanel.java:480)
	at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
	at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
	at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254)
	at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
	at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
	at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
	at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
	at com.intellij.util.Alarm$Request$1.run(Alarm.java:351)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)

xml:

<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity$PlaceholderFragment">

    <TextView android:id="@+id/section_label" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>

Activity(No code errors here but I am surprised to see calls of deprecated functions in a demo code):

import java.util.Locale;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.FragmentPagerAdapter;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


public class MainActivity extends ActionBarActivity implements ActionBar.TabListener {

    /**
     * The {@link android.support.v4.view.PagerAdapter} that will provide
     * fragments for each of the sections. We use a
     * {@link FragmentPagerAdapter} derivative, which will keep every
     * loaded fragment in memory. If this becomes too memory intensive, it
     * may be best to switch to a
     * {@link android.support.v4.app.FragmentStatePagerAdapter}.
     */
    SectionsPagerAdapter mSectionsPagerAdapter;

    /**
     * The {@link ViewPager} that will host the section contents.
     */
    ViewPager mViewPager;

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

        // Set up the action bar.
        final ActionBar actionBar = getSupportActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        // Create the adapter that will return a fragment for each of the three
        // primary sections of the activity.
        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

        // Set up the ViewPager with the sections adapter.
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        // When swiping between different sections, select the corresponding
        // tab. We can also use ActionBar.Tab#select() to do this if we have
        // a reference to the Tab.
        mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                actionBar.setSelectedNavigationItem(position);
            }
        });

        // For each of the sections in the app, add a tab to the action bar.
        for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
            // Create a tab with text corresponding to the page title defined by
            // the adapter. Also specify this Activity object, which implements
            // the TabListener interface, as the callback (listener) for when
            // this tab is selected.
            actionBar.addTab(
                    actionBar.newTab()
                            .setText(mSectionsPagerAdapter.getPageTitle(i))
                            .setTabListener(this));
        }
    }


    @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) {
        // 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);
    }

    @Override
    public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
        // When the given tab is selected, switch to the corresponding page in
        // the ViewPager.
        mViewPager.setCurrentItem(tab.getPosition());
    }

    @Override
    public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
    }

    @Override
    public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
    }

    /**
     * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
     * one of the sections/tabs/pages.
     */
    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;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            Locale l = Locale.getDefault();
            switch (position) {
                case 0:
                    return getString(R.string.title_section1).toUpperCase(l);
                case 1:
                    return getString(R.string.title_section2).toUpperCase(l);
                case 2:
                    return getString(R.string.title_section3).toUpperCase(l);
            }
            return null;
        }
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    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";

        /**
         * 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;
        }

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            return rootView;
        }
    }

}

Android Solutions


Solution 1 - Android

Had the exact same problem. I got rid of it by changing res/values/styles.xml to

<!-- Base application theme. -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>

Solution 2 - Android

The Android Tools Project website lists this as a known bug of version 1.2 of the Android Gradle plugin, and declare it will be fixed by version 1.2.3

See: http://tools.android.com/knownissues

They propose 3 workarounds:

Quote the above link:

> Workaround 1: First manually build the project, then manually sync the > project (using the Sync with Gradle files in the toolbar, or from the > Tools > Android menu), then finally press Refresh in the toolbar above > the layout editor. > > Workaround 2: Switch the Android Gradle plugin from 1.2.x to 1.1.3 for > now. When 1.2.3 is released you can switch back to the 1.2.x versions. > > Workaround 3: If the above workarounds don't work for you, and you are > on windows, please try downloading a build from [link in website]

Solution 3 - Android

I had the same issue, I think it's an issue while rendering AppCompatTheme.

to enable preview again switch to a stock theme like "Material Light" / "Material.Light.DarkActionBarTheme"

Solution 4 - Android

I had the same error. The solution was:

  • First you have to Sync your project.
  • Next, go to Build menu, and clic on the Clean Project.
  • Finally, again, go to Build menu, and clic on the Rebuild option.

No need to change a thing, and works like a charm.

Solution 5 - Android

I used <style name="AppTheme" parent="android:Theme.Light">in my styles.xml and it worked.

Solution 6 - Android

I had this error from an absolutely new project, created by Android Studio 1.2.

@florent's solution worked for me:

> switch to a stock theme like "Material Light" / "Material.Light.DarkActionBarTheme"

Changed this, built the project, and the render started to work.

Solution 7 - Android

I resolved it by changing the values under: Relative Layout -> Properties -> Padding | to numeric values instead of default value. Then hit Rebuild.

Solution 8 - Android

For me, the fix was to use the latest gradle version

Solution 9 - Android

by changing res/values/styles.xml to

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. --> 

do DarkActionBarTheme or NoActionBar

Solution 10 - Android

Android Studio 3.0

On the right-top side, you can see AppTheme. Click on it, from the dropdown choose 'Material Light' or something other than default.

Solution 11 - Android

I was facing the same issue. It is some rendering issue with the AppCompat themes. So I made changes to the styles.xml file as follows:

<style name="AppTheme" parent ="android:Theme.Holo.Light.DarkActionBar">
</style>

So the issue resolved.However if we still want to use the AppCompat themes, what should be done, I have not yet found out.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser3782779View Question on Stackoverflow
Solution 1 - AndroidpasqlView Answer on Stackoverflow
Solution 2 - AndroidIftahView Answer on Stackoverflow
Solution 3 - Androidflorent champignyView Answer on Stackoverflow
Solution 4 - AndroidFrancisco OsnayaView Answer on Stackoverflow
Solution 5 - AndroidshahdView Answer on Stackoverflow
Solution 6 - AndroidAnthony M. PowersView Answer on Stackoverflow
Solution 7 - AndroidRadek OView Answer on Stackoverflow
Solution 8 - AndroidnotdroneView Answer on Stackoverflow
Solution 9 - AndroidAlwayss BijoyView Answer on Stackoverflow
Solution 10 - AndroidDhaval JardoshView Answer on Stackoverflow
Solution 11 - AndroidSabUView Answer on Stackoverflow