Search code examples
xamarinxamarin.androidmvvmcross

Error when try to inflate coordinator Layout


I get this exception when I try to inflate a layout to my main activity who contains a coordinator layout:

04-06 16:18:17.434 I/mono-stdout( 2690): InnerException was IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.
    04-06 16:18:17.434 I/mono-stdout( 2690):      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 
    04-06 16:18:17.435 I/mono-stdout( 2690):   at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (IntPtr jobject, IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00084] in /Users/builder/data/lanes/3053/a94a03b5/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:1029 
    04-06 16:18:17.435 I/mono-stdout( 2690):   at Android.Runtime.JNIEnv.FinishCreateInstance (IntPtr instance, IntPtr jclass, IntPtr constructorId, Android.Runtime.JValue* constructorParameters) [0x0000b] in /Users/builder/data/lanes/3053/a94a03b5/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:306 
    04-06 16:18:17.435 I/mono-stdout( 2690):   at Android.Support.Design.Widget.CoordinatorLayout..ctor (Android.Content.Context context, IAttributeSet attrs) [0x000f9] in <filename unknown>:0 
    04-06 16:18:17.435 I/mono-stdout( 2690):   at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
    04-06 16:18:17.435 I/mono-stdout( 2690):   at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:644 
    04-06 16:18:17.435 I/mono-stdout( 2690):   --- End of managed exception stack trace ---
    04-06 16:18:17.436 I/mono-stdout( 2690): java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.
    04-06 16:18:17.436 I/mono-stdout( 2690):    at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:34)
    04-06 16:18:17.436 I/mono-stdout( 2690):    at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:182)
    04-06 16:18:17.436 I/mono-stdout( 2690):    at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:176)
    04-06 16:18:17.437 I/mono-stdout( 2690):    at md5bf0126c95bf9fc0db24c02c9adb4cfa7.MvxLayoutInflater_PrivateFactoryWrapper2.n_onCreateView(Native Method)
    04-06 16:18:17.437 I/mono-stdout( 2690):    at md5bf0126c95bf9fc0db24c02c9adb4cfa7.MvxLayoutInflater_PrivateFactoryWrapper2.onCreateView(MvxLayoutInflater_PrivateFactoryWrapper2.java:31)
    04-06 16:18:17.437 I/mono-stdout( 2690):    at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:186)
    04-06 16:18:17.437 I/mono-stdout( 2690):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:754)
    04-06 16:18:17.437 I/mono-stdout( 2690):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
    04-06 16:18:17.437 I/mono-stdout( 2690):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at moneyfox.droid.activities.MainActivity.n_onCreate(Native Method)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at moneyfox.droid.activities.MainActivity.onCreate(MainActivity.java:30)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.app.Activity.performCreate(Activity.java:6237)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.app.ActivityThread.-wrap11(ActivityThread.java)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.os.Handler.dispatchMessage(Handler.java:102)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.os.Looper.loop(Looper.java:148)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at android.app.ActivityThread.main(ActivityThread.java:5417)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at java.lang.reflect.Method.invoke(Native Method)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    04-06 16:18:17.438 I/mono-stdout( 2690):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    Unhandled Exception:

    Android.Views.InflateException: Binary XML file line #1: Error inflating class android.support.design.widget.CoordinatorLayout

But I already use the AppCompat theme:

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">

Layout for Main Activity:

xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_height="match_parent"
    android:layout_width="match_parent">
    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/main_frame"
        android:fitsSystemWindows="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerInParent="true" />
    </android.support.design.widget.CoordinatorLayout>
    <FrameLayout
        android:id="@+id/navigation_frame"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_gravity="left|start" />
</android.support.v4.widget.DrawerLayout>

Also I found post who saied I have to set the windowActionBar and windowNoTitle Tags, what I already did.

The whole code is based on the sample in the mvvm cross repo.

Funny enough I found that the error started appearing when I updated to the new version of the support.design package. is there anything I can do to avoid this?


Solution

  • I found the issue.. I haven't added the MvvmCross.Droid.Support.Design Nuget Package...

    https://www.nuget.org/packages/MvvmCross.Droid.Support.Design/

    After I added it, cleaned the solution and restarted VS it works..