-1

I am getting this error and I don't know how to fix it. I searched, and found solutions like setting the theme and changing it, even duplicate libraries but nothing fixed it!

My Error:

Error

My Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.company.app">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="com.android.vending.BILLING" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="SLUITEN" />
            </intent-filter>
        </activity>
        <activity
            android:name=".CustomSettings"
            android:label="@string/title_activity_custom_settings"
            android:theme="@style/AppTheme" />
        <activity android:name=".aantekeningen.Aantekeningen" />
        <activity
            android:name="com.example.avjindersinghsekhon.minimaltodo.MainActivity"
            android:theme="@style/AppThemed"
            android:launchMode="singleTop"
            android:screenOrientation="portrait"
            />


        <activity android:name="com.example.avjindersinghsekhon.minimaltodo.AddToDoActivity"
            android:screenOrientation="portrait"
            android:parentActivityName="com.example.avjindersinghsekhon.minimaltodo.MainActivity"
            />

        <activity android:name="com.example.avjindersinghsekhon.minimaltodo.AboutActivity"
            android:label="@string/app_name"
            android:parentActivityName="com.example.avjindersinghsekhon.minimaltodo.MainActivity"
            />

        <activity android:name="com.example.avjindersinghsekhon.minimaltodo.ReminderActivity"
            android:label="@string/app_name"
            />

        <service android:name="com.example.avjindersinghsekhon.minimaltodo.TodoNotificationService"
            />
        <service android:name="com.example.avjindersinghsekhon.minimaltodo.DeleteNotificationService"
            />
        <activity android:name="com.example.avjindersinghsekhon.minimaltodo.SettingsActivity"
            android:parentActivityName="com.example.avjindersinghsekhon.minimaltodo.MainActivity"

            />

        <receiver android:name=".ScheduleWidget">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>

            <meta-data
                android:name="android.appwidget.provider"
                android:resource="@xml/schedule_widget_info" />
        </receiver>

        <activity
            android:name=".CustomHours"
            android:label="Aangepaste uren"
            android:theme="@style/AppTheme"
            android:windowSoftInputMode="stateAlwaysHidden" />
    </application>

</manifest>

My layout XML File

    <include layout="@layout/base_toolbar"/>
    <android.support.design.widget.CoordinatorLayout
            android:id="@+id/myCoordinatorLayout"
            android:layout_width="match_parent"
            android:gravity="center"
            android:layout_height="match_parent"
            >

        <LinearLayout
            android:id="@+id/toDoEmptyView"
            android:orientation="vertical"
            android:gravity="center"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:src="@drawable/empty_view_bg"
                android:layout_width="100dp"
                android:layout_height="100dp" />
            <TextView
                android:text="@string/no_to_dos"
                android:textColor="@color/secondary_text"
                android:textSize="16sp"
                android:paddingTop="4dp"
                android:paddingBottom="8dp"
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </LinearLayout>

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:elevation="0dp"
            android:elevation="0dp"
            >

            <include layout="@layout/base_toolbar"/>
        </android.support.design.widget.AppBarLayout>

            <!--<include layout="@layout/base_toolbar"/>-->


        <!--</android.support.design.widget.AppBarLayout>-->


            <com.example.avjindersinghsekhon.minimaltodo.RecyclerViewEmptySupport
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                android:id="@+id/toDoRecyclerView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>


        <android.support.design.widget.FloatingActionButton
            android:src="@drawable/ic_add_white_24dp"
            android:id="@+id/addToDoItemFAB"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="16dp"
            app:layout_anchor="@id/myCoordinatorLayout"
            app:layout_anchorGravity="bottom|right|end"
            app:layout_behavior="com.example.avjindersinghsekhon.minimaltodo.ScrollingFABBehaviour"
            />


    </android.support.design.widget.CoordinatorLayout>
</LinearLayout>

My styles.xml

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <style name="AppThemeGrey" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorGrey</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowActionBar">false</item>
    </style>
    <style name="MyRandomTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/amber</item>
        <item name="colorPrimaryDark">@color/amberPressed</item>
        <item name="colorAccent">@color/amber</item>
    </style>
    <style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
        <item name="android:textColor">#ff9800</item>
    </style>
    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
    <style name="CustomStyle" parent="Theme.AppCompat.NoActionBar">
        <item name="colorAccent">@color/colorAccent</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorSwitchThumbNormal">@color/grey300</item>
        <item name="android:colorForeground">@color/grey600</item>
    </style>
    <style name="CustomStyle.DarkTheme" parent="Theme.AppCompat">
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="colorAccent">@color/amber</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorSwitchThumbNormal">@color/grey300</item>
        <item name="android:colorForeground">@color/grey600</item>
    </style>
    <style name="PopupMenuLight" parent="Widget.AppCompat.PopupMenu">
        <item name="android:popupBackground">@android:color/black</item>
    </style>
    <style name="OverflowThreeDotsWhite" parent="Widget.AppCompat.Light.ActionButton.Overflow">
        <item name="android:src">@drawable/ic_menu_overflow_light</item>
    </style>
    <style name="ToolBarTheme" parent="Widget.AppCompat.Toolbar">
        <item name="titleTextAppearance">@style/ToolbarTitleTextAppearanceLight</item>
    </style>
    <style name="ToolbarTitleTextAppearanceLight" parent="Base.TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@android:color/white</item>
    </style>
    <style name="ToolbarTitleTextAppearanceDark" parent="Base.TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@color/amber</item>
    </style>
    <style name="CustomStyle.LightTheme" parent="Theme.AppCompat.Light">
        <item name="actionOverflowButtonStyle">@style/OverflowThreeDotsWhite</item>
        <item name="toolbarStyle">@style/ToolBarTheme</item>
        <item name="popupMenuStyle">@style/PopupMenuLight</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorSwitchThumbNormal">@color/grey300</item>
        <item name="android:colorForeground">@color/grey600</item>
    </style>
    <style name="CustomToolbar" parent="Widget.AppCompat.ActionBar">
        <item name="theme">@style/CustomToolbarTheme</item>
    </style>
    <style name="CustomToolbarTheme" parent="ThemeOverlay.AppCompat.ActionBar">
        <item name="android:textColorPrimary">@color/secondary_text</item>
    </style>
    <style name="CustomCheckbox" parent="Widget.AppCompat.CompoundButton.CheckBox">
        <item name="android:button">@color/amber</item>
    </style>
    <style name="AppTheme.ToolBarPadding" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="toolbarStyle">@style/myToolBarStyle</item>
    </style>
    <style name="CustomDialog" parent="Base.Theme.AppCompat.Light.Dialog">
        <item name="colorAccent">@color/colorPrimary</item>
    </style>
    <style name="CustomSwitch" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorSwitchThumbNormal">@color/amber</item>
        <item name="android:colorForeground">@color/secondary_text</item>
    </style>
    <style name="myToolBarStyle" parent="@style/Widget.AppCompat.Toolbar">
        <item name="android:paddingRight">32dp</item>
    </style>
    <style name="FloatingLabelTextAppearance" parent="TextAppearance.AppCompat">
        <item name="android:textColor">@android:color/white</item>
    </style>
    <style name="AppThemed" parent="Theme.AppCompat">
        <!-- Customize your theme here. -->
        <item name="android:windowActionBar">false</item>
    </style>
</resources>


EDIT:

Error when launching app:

FATAL EXCEPTION: main
Process: com.company.app, PID: 31597
java.lang.IllegalStateException: View can not be anchored to the the parent CoordinatorLayout
    at android.support.design.widget.CoordinatorLayout$LayoutParams.resolveAnchorView(CoordinatorLayout.java:2526)
    at android.support.design.widget.CoordinatorLayout$LayoutParams.findAnchorView(CoordinatorLayout.java:2495)
    at android.support.design.widget.CoordinatorLayout.prepareChildren(CoordinatorLayout.java:623)
    at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:674)
    at android.view.View.measure(View.java:17547)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
    at android.view.View.measure(View.java:17547)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
    at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
    at android.view.View.measure(View.java:17547)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
    at android.view.View.measure(View.java:17547)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
    at android.view.View.measure(View.java:17547)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
    at android.view.View.measure(View.java:17547)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2615)
    at android.view.View.measure(View.java:17547)
    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2015)
    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1173)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1379)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
    at android.view.Choreographer.doCallbacks(Choreographer.java:580)
    at android.view.Choreographer.doFrame(Choreographer.java:550)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5254)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
halfer
  • 18,701
  • 13
  • 79
  • 158
Jason
  • 1,363
  • 3
  • 12
  • 42
  • 1
    Did you set the theme above the preview (dropdown next to the device e.g Nexus 5). – Vucko Jul 15 '16 at 11:59
  • 1
    what is your android support design library version. – Sagar Chavada Jul 15 '16 at 12:33
  • and also there is no error.. its only display rendring issue,, when you initialize on java class.. it will be solved.. just ignore it.. – Sagar Chavada Jul 15 '16 at 12:35
  • Is it just a problem on the preview? Is it working on the device? If it works in the device why do you care about the preview? – Xaver Kapeller Jul 15 '16 at 12:45
  • 1
    @XaverKapeller It does not work when I launch it, see the error I added below – Jason Jul 15 '16 at 12:49
  • According to the error in your logcat the problem is something about your CoordinatorLayout. It has nothing to do with themes: `View can not be anchored to the the parent CoordinatorLayout`. – Xaver Kapeller Jul 15 '16 at 12:51
  • To be more specific this is the problem: `app:layout_anchor="@id/myCoordinatorLayout"` – Xaver Kapeller Jul 15 '16 at 12:52
  • Possible duplicate of [View can not be anchored to the the parent CoordinatorLayout](http://stackoverflow.com/questions/35747736/view-can-not-be-anchored-to-the-the-parent-coordinatorlayout) – Bill Jul 15 '16 at 12:53
  • Why are you trying to anchor a view to the `CoordinatorLayout` itself? What's that supposed to do? I assume you actually want to anchor the button to the `AppBarLayout`, right? Then give the `AppBarLayout` an id and refer to it in the `app:layout_anchor` attribute. – Xaver Kapeller Jul 15 '16 at 12:54
  • So in the future: Actually read the stack trace, it tells you everything you need to know. – Xaver Kapeller Jul 15 '16 at 12:55
  • 1
    @XaverKapeller it worked!! Thank you! I just added an ID to the appbarlayout and it worked! – Jason Jul 15 '16 at 13:02
  • I can't speak to that, I can just tell you that this is wrong and that the open source app doesn't use that as well. – Xaver Kapeller Jul 15 '16 at 13:02
  • Glad to have helped. – Xaver Kapeller Jul 15 '16 at 13:03

1 Answers1

0

The solution is:

According to @XaverKapeller "Then give the AppBarLayout an id and refer to it in the app:layout_anchor attribute."

This solution worked
Thank you @XaverKapeller

Jason
  • 1,363
  • 3
  • 12
  • 42