gpt4 book ai didi

android - 协调器布局和一些其他布局在迁移到 androidX 后不起作用

转载 作者:行者123 更新时间:2023-11-29 18:30:08 25 4
gpt4 key购买 nike

我最近使用 Refactor 将我的项目迁移到 androidX。所有实现都自动更改为 androidx。但我无法使用支持设计布局示例:Coordinator Layout整个预览只显示灰色。

我用谷歌搜索并尝试了一些修复,例如更改 taregtSKD 版本,但没有任何帮助。我不知道我做错了什么。

这是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'

}

我尝试使用 Coordinator Layout 使用

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

那是行不通的![同时所有插件都更新到最新版本]请帮助..

更新添加后

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

布局正常,gradle 构建没有任何错误。但是,当我运行该应用程序时,它仍然崩溃并出现此错误

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)

由于我的应用程序在迁移之前没有任何错误地运行,我猜这些错误是由于 androidx.请弄清楚。谢谢

最佳答案

你可以试试稳定版

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

然后清理-重建-运行。

仅供引用

NullPointerException当应用程序尝试使用具有空值的对象引用时抛出。

关于android - 协调器布局和一些其他布局在迁移到 androidX 后不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56733940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com