Pratham Vaidya
Pratham Vaidya

Reputation: 105

Coordinator Layout and some other layouts not working after migration to androidX

I recently migrated my project to androidX using Refactor. All the implementations were automatically changed to androidx. But I am not able use support design layouts example: Coordinator Layout It is only showing grey color on the whole preview.

I googled and tried some fixes like changing the taregtSKDversion but nothing really helped. I have no idea what am I doing wrong.

This is build.gradle [app]

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.pratham.sitapuriya"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0-beta01'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.1.0-alpha07'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.3.0-alpha01'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha01'
    implementation 'com.android.volley:volley:1.1.1'
    implementation 'com.google.android.material:material:1.1.0-alpha07'
    repositories {
        mavenCentral()
        google()
    }

    dependencies {
        implementation 'com.github.bumptech.glide:glide:4.9.0'
        annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
    }

    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    dependencies {
        implementation 'com.facebook.shimmer:shimmer:0.1.0@aar'
    }
    implementation 'com.github.marlonlom:timeago:4.0.1'

}

I tried to use Coordinator Layout using

<androidx.coordinatorlayout.widget.CoordinatorLayout >
 // Other Childs
</<androidx.coordinatorlayout.widget.CoordinatorLayout>

And that wasn't working! [Also all plugins are updated to latest version] Please help..

UPDATE After adding

    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

The layout was working and gradle was build without any error. But still when I run the app then it crashed giving this error

06-24 12:11:34.212 18074-18074/com.pratham.sitapuriya E/dalvikvm: Could not find class 'androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper', referenced from method androidx.core.view.ViewCompat.addOnUnhandledKeyEventListener
06-24 12:11:34.216 18074-18074/com.pratham.sitapuriya E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method androidx.core.view.ViewCompat.dispatchApplyWindowInsets
06-24 12:11:34.228 18074-18074/com.pratham.sitapuriya E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method androidx.core.view.ViewCompat.onApplyWindowInsets
06-24 12:11:34.229 18074-18074/com.pratham.sitapuriya E/dalvikvm: Could not find class 'android.view.View$OnUnhandledKeyEventListener', referenced from method androidx.core.view.ViewCompat.removeOnUnhandledKeyEventListener
06-24 12:11:34.239 18074-18074/com.pratham.sitapuriya E/dalvikvm: Could not find class 'androidx.core.view.ViewCompat$1', referenced from method androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener
06-24 12:11:37.983 18074-18074/com.pratham.sitapuriya E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.button.MaterialButtonHelper.unwrapBackgroundDrawable
06-24 12:11:37.989 18074-18074/com.pratham.sitapuriya E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.button.MaterialButtonHelper.unwrapStrokeDrawable
06-24 12:11:37.992 18074-18074/com.pratham.sitapuriya E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.google.android.material.button.MaterialButtonHelper.setRippleColor
06-24 12:11:38.022 18074-18074/com.pratham.sitapuriya E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.pratham.sitapuriya, PID: 18074
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pratham.sitapuriya/com.pratham.sitapuriya.AccountActivity}: java.lang.NullPointerException
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2433)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2484)
        at android.app.ActivityThread.access$800(ActivityThread.java:158)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1391)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:5486)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
        at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
        at com.pratham.sitapuriya.AppunctionsKt.beautifyLayout(appunctions.kt:76)
        at com.pratham.sitapuriya.AccountActivity.onCreate(AccountActivity.kt:14)

As My app was working without any errors before migration i guess these errors are due to androidx. Please figure it out. Thanks

Upvotes: 1

Views: 733

Answers (1)

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75788

You can try with Stable version

    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

Then Clean-Rebuild-Run.

FYI

NullPointerException is thrown when an application attempts to use an object reference that has the null value.

Upvotes: 3

Related Questions