gpt4 book ai didi

java - 为什么我收到错误? : parameter t has incompatible upper bounds: Preference and Preference

转载 作者:行者123 更新时间:2023-12-02 09:21:12 26 4
gpt4 key购买 nike

我无法解决错误的问题:

incompatible types: no unique maximal instance exists for type variable T with upper bounds com.velocat.cmap.Preference,androidx.preference.Preference
Preference preference = findPreference("button");
^
where T is a type-variable:
T extends androidx.preference.Preference declared in method <T>findPreference(CharSequence)

SettingsFragment.java

import android.os.Bundle;
import android.preference.Preference;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.preference.PreferenceFragmentCompat;

public class SettingsFragmentActivity extends PreferenceFragmentCompat {

Preference preference;
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {

addPreferencesFromResource(R.xml.setting);

Preference preference = findPreference("preference1");
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

View view = super.onCreateView(inflater, container, savedInstanceState);

return view;
}

}

buld.gradle的一部分

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.1.0'
implementation 'androidx.navigation:navigation-ui:2.1.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.preference:preference:1.1.0'

}

xml/settings.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<SwitchPreference
android:defaultValue="false"
android:key="preference1"
android:title="test" />
</PreferenceScreen>

我重新阅读了搜索中所有可能的内容,但没有找到问题的解决方案。有谁知道如何消除这个错误?

如果您对此主题有任何澄清,我将不胜感激。

最佳答案

我猜你输入了错误的首选项,它应该是

import androidx.preference.Preference

当您扩展androidx.preference.PreferenceFragmentCompat并按照docs它返回

androidx.preference.Preference

关于java - 为什么我收到错误? : parameter t has incompatible upper bounds: Preference and Preference,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58684399/

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