gpt4 book ai didi

android - 类型不匹配 : inferred type is LoginActivity but LifecycleOwner was expected

转载 作者:IT老高 更新时间:2023-10-28 13:35:29 30 4
gpt4 key购买 nike

我正在玩 AndroidStudio - 3.4 Canary 9 的预览版。

我从 Configure your project 窗口中选择了默认登录 Activity 选项,并提供了以下选项:

Configure your project

Gradle 同步没有报告错误,但是在构建编译时会产生以下错误:

Type mismatch: inferred type is LoginActivity but LifecycleOwner was expected

这是显示错误的代码 fragment :

// Type mismatch at this@LoginActivity, required LifeCycleOwner, found - LoginActivity
loginViewModel.loginFormState.observe(this@LoginActivity, Observer {
val loginState = it ?: return@Observer

// disable login button unless both username / password is valid
login.isEnabled = loginState.isDataValid

if (loginState.usernameError != null) {
username.error = getString(loginState.usernameError)
}
if (loginState.passwordError != null) {
password.error = getString(loginState.passwordError)
}
})

LoginActivity 派生自 AppCompatActivity()

各自导入的库是androidx.appcompat.app.AppCompatActivity

这是来自应用级 build.gradle 的内容:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.socialsample"
minSdkVersion 19
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.0.2'
implementation 'androidx.core:core-ktx:1.1.0-alpha03'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.annotation:annotation:1.0.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

这是来自项目级 build.gradle 的内容:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.11'
repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0-alpha09'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
jcenter()

}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

我在这里有什么遗漏吗?请提出建议。

最佳答案

我遇到了同样的问题,并通过将我的支持版本更新到来修复它

versions.support = "1.1.0-alpha01"

所以这意味着只需更新

实现'androidx.appcompat:appcompat:1.1.0-alpha01'

它应该被修复

关于android - 类型不匹配 : inferred type is LoginActivity but LifecycleOwner was expected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54021453/

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