当前位置: 首页 > 知识库问答 >
问题:

Android Studio将我的小部件标记为不兼容类型

曾鸿振
2023-03-14

我有多个小部件,您通常会这样初始化这些小部件,

 public EditText editTextTitle;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_job);

    editTextTitle = findViewById(R.id.editTxtTitle);
}

然而,当我转到xml时,它显示它实际上是一个EditText。

这一切都发生在我改变我的build.gradle(应用程序)的时候

apply plugin: 'com.android.application'

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

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.google.firebase:firebase-core:17.0.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.firebase:firebase-firestore:20.2.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.mikhaellopez:circularimageview:3.2.0'
}

apply plugin: 'com.google.gms.google-services'

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            // Skip multidex because it follows a different versioning pattern.
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.3.0'
            }
        }
    }
}

共有1个答案

郎雅昶
2023-03-14

您正在以错误的方式使用multidexing。请参阅以下参考资料。https://developer.android.com/studio/build/multidex.html

此外,您应该迁移到androidx,以获得现有支持库的新特性和升级。

删除以下代码,因为它正在尝试使用旧版本的支持库。

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            // Skip multidex because it follows a different versioning pattern.
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.3.0'
            }
        }
    }
}
apply plugin: 'com.android.application'

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

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.google.firebase:firebase-core:17.0.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.firebase:firebase-firestore:20.2.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.mikhaellopez:circularimageview:3.2.0'
}

更新

修复多德兴后,观察到相关代码跟随错误

它是由于在非androidx项目上混合了androidx库com.mikhaellopez:circularImageView:3.2.0造成的。该项目应该迁移到andoridx以使用androidx库。

 类似资料:
  • 我正在尝试使用Apache OpenNLP API创建一个标记器。我已经从他们的网站中提取了代码,但在Tokenize类中,以下代码行出现了“不兼容类型”错误: Tokenize Tokenizer=new TokenizerME(模型); 有人知道这个错误的原因吗?因为看起来他们不应该不兼容? 这是主要类: 这是具有错误的Tokenize类:

  • 我试图通过在一个单独的线程上进行工作并返回所需的对象来更改JavaFX中的GUI。然而,在完成工作和任务之后。setOnSucceeded()在尝试检索创建的对象时被触发,并出现错误“不兼容类型:对象无法转换为VideoScrollPane类型”。 我认为这与原始类型有关,因为这是在听众中发生的,但环顾四周后,我找不到我想要的建议。 任何可以散发的光芒都将不胜感激。

  • 问题内容: 我试图通过在单独的线程上进行工作并返回所需的对象来对JavaFX中的GUI进行更改。但是,在完成工作和task.setOnSucceeded()之后,我尝试检索创建的对象并得到错误“不兼容的类型:对象无法转换为VideoScrollPane类型”。 我认为这与原始类型有关,因为它发生在侦听器中,但是四处查看后,我找不到我想要的建议。 任何可以散发出的光将不胜感激。 问题答案: 这是因为

  • 问题内容: 我一直在与以下名为 并试图将其转换为一个名为作为 但是转向这种表示形式,我们的单元测试之一开始失败。这些测试在内部处理从JSON文件读取并映射到对象的城市列表,进一步将城市分组到一个城市中。简化为: 上面的代码断言为true,其中包含4个密钥,每个密钥占其出现次数的1。使用记录表示法,结果中的键不超过3个。是什么原因造成的,解决该问题的方法应该是什么? 问题答案: 原因 观察到的行为背

  • 但是当我们转向这样的表示时,我们的一个单元测试开始失败。测试在内部处理从JSON文件读取并映射到对象的城市列表,进一步计算城市数,同时将它们分组到中。简化为: 上面的代码断言为true,以包含4个键,每个键占其出现次数的1。使用记录表示法,生成的中的键不超过3个。是什么造成了这种情况?应该采取什么办法来解决这种情况?

  • 我试图编译一个从SourceForge得到的仍在开发中的项目。这是它的地址:。https://sourceforge.net/p/groove/code/5475/tree/groove/trunk/我知道这个项目经过了很好的验证,它没有任何错误,但是当我要编译它的时候,我遇到了这个编译错误: 错误在这个文件的第370行:https://sourceforge.net/p/groove/code/