Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio XML preview not showing

There is something wrong with the AppBarLayout.

UPDATE: This is a new error. The XML view preview doesn't show anything. The normal Design View shows a preview but nothing is clickable on it.

java.lang.IllegalArgumentException: object is not an instance of declaring class

Here is the error:

java.lang.IllegalArgumentException: java.lang.ClassCastException@24bbb842
at sun.reflect.GeneratedMethodAccessor319.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at android.animation.PropertyValuesHolder_Delegate.callMethod(PropertyValuesHolder_Delegate.java:108)
at android.animation.PropertyValuesHolder_Delegate.nCallFloatMethod(PropertyValuesHolder_Delegate.java:143)
at android.animation.PropertyValuesHolder.nCallFloatMethod(PropertyValuesHolder.java)
at android.animation.PropertyValuesHolder.access$400(PropertyValuesHolder.java:38)
at android.animation.PropertyValuesHolder$FloatPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:1387)
at android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:990)
at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:674)
at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:637)
at android.animation.ValueAnimator.start(ValueAnimator.java:1069)
at android.animation.ValueAnimator.start(ValueAnimator.java:1088)
at android.animation.ObjectAnimator.start(ObjectAnimator.java:852)
at android.animation.StateListAnimator.start(StateListAnimator.java:188)
at android.animation.StateListAnimator.setState(StateListAnimator.java:181)
at android.view.View.drawableStateChanged(View.java:21105)
at android.view.ViewGroup.drawableStateChanged(ViewGroup.java:7101)
at com.google.android.material.appbar.AppBarLayout.drawableStateChanged(AppBarLayout.java:393)
at android.view.View.refreshDrawableState(View.java:21160)
at android.view.View.dispatchAttachedToWindow(View.java:18379)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3397)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)
at android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:42)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:335)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:391)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:195)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:540)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$5(RenderTask.java:666)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

Here's my XML:

<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:theme="@style/ToolbarWhiteText"
        app:logo="@drawable/vector_logo">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="24dp"
            android:gravity="start|center_vertical"
            android:text="@string/title_profile"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="@color/white"
            android:textSize="16sp"
            android:textStyle="bold" />
    </androidx.appcompat.widget.Toolbar>

</com.google.android.material.appbar.AppBarLayout>

Gradle dependencies (I know they're a lot)

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

// Core
implementation 'androidx.appcompat:appcompat:1.1.0-alpha05'
implementation 'com.google.android.material:material:1.1.0-alpha06'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta1'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha05'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
// Google
implementation "com.google.android.gms:play-services-location:$playServicesVersion"
implementation "com.google.android.gms:play-services-places:$playServicesVersion"
implementation "com.google.android.gms:play-services-maps:$playServicesVersion"
implementation "com.google.android.gms:play-services-auth:$playServicesVersion"
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
implementation "com.google.firebase:firebase-messaging:$firebaseMessagingVersion"
implementation "com.google.maps:google-maps-services:$googleMapServicesVersion"
// Retrofit and Moshi
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
implementation "com.squareup.retrofit2:converter-moshi:$retrofitVersion"
// Butterknife
implementation "com.jakewharton:butterknife:$butterknifeVersion"
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta1'
annotationProcessor "com.jakewharton:butterknife-compiler:$butterknifeVersion"
// EasyPermissions
implementation "pub.devrel:easypermissions:$easyPermissionsVersion"
// Toasty
implementation "com.github.GrenderG:Toasty:$toastyVersion"
// CardIO
/*implementation "io.card:android-sdk:$cardIoVersion"*/

// MaterialDialog
implementation "com.afollestad.material-dialogs:core:$materialDialogsVersion"
// Material Drawer
implementation("com.mikepenz:materialdrawer:$materialDrawerVersion") { transitive = true }
implementation 'androidx.annotation:annotation:1.1.0-rc01'
// NiceSpinner
implementation "com.github.arcadefire:nice-spinner:$niceSpinnerVersion"
// Circle ImageView
implementation "de.hdodenhof:circleimageview:$circleImageViewVersion"
// Socket.IO
implementation("io.socket:socket.io-client:$socketIOVersion") {
    exclude group: 'org.json', module: 'json'
}

implementation "com.dinuscxj:circleprogressbar:$circularProgressVersion"
implementation("com.wdullaer:materialdatetimepicker:$materialDateTimeVersion") {
    exclude group: 'androidx.appcompat'
    exclude group: 'androidx.recyclerview'
}
implementation "com.azoft.carousellayoutmanager:carousel:$carouselLayoutManager"
implementation "com.google.maps.android:android-maps-utils:$mapUtilsVersion"

/*implementation "android.arch.lifecycle:extensions:$architectureVersion"
implementation "android.arch.lifecycle:runtime:$architectureVersion"*/
implementation 'androidx.room:room-runtime:2.1.0-beta01'
annotationProcessor 'androidx.room:room-compiler:2.1.0-beta01'

implementation "com.github.bumptech.glide:glide:$glideVersion"
annotationProcessor "com.github.bumptech.glide:compiler:$glideVersion"

implementation "com.evernote:android-job:$androidJobVersion"

implementation 'com.github.stfalcon:chatkit:0.3.3'

implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0'
implementation 'com.devlomi.record-view:record-view:2.0.1'
implementation 'net.alexandroid.utils:exoplayerhelper:2.18'
implementation 'net.alhazmy13.MediaPicker:libary:2.4.4'
implementation 'com.stripe:stripe-android:6.1.2'
implementation 'com.applandeo:material-calendar-view:1.5.1'

implementation 'com.braintreepayments.api:drop-in:3.+'
implementation 'com.braintreepayments.api:braintree:2.+'

implementation 'com.facebook.android:facebook-login:[4,5)'

}

like image 475
Asim Avatar asked May 10 '19 19:05

Asim


1 Answers

I had the same issue it seems some problem with the alpha material library I downgraded the material library dependency in the build.gradle to
implementation 'com.google.android.material:material:1.0.0'
then invalidated the cache and restarted the studio from
File -> Invalidate Caches / Restart...
It worked.

like image 76
Avinash Joshi Avatar answered Oct 19 '22 18:10

Avinash Joshi