簡體   English   中英

如何修復 Android Studio 中的“Incompatible Types”錯誤?

[英]How to fix "Incompatible Types" error in Android Studio?

我是 Android Studio 的初學者,正在將初學者項目作為聊天應用程序工作。 工作 oc Fragment 類出現問題:“不兼容的類型”

我在互聯網上嘗試了其他我發現但沒有奏效的解決方案。

這是我的課:

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

public class TabsAdapter extends FragmentPagerAdapter {
    public TabsAdapter(@NonNull FragmentManager fm) {
        super(fm);
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {

        switch (position){

            case 0:
                RequestFragment requestfragment = new RequestFragment();
                return requestfragment;
        }
        return null;
    }

    @Override
    public int getCount() {
        return 0;
    }
}

這是我的 Gradle:

compileSdkVersion 29
buildToolsVersion '29.0.1'
minSdkVersion 21
targetSdkVersion 29

            implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
            implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
            implementation 'com.google.android.material:material:1.1.0-alpha07'
            testİmplementation 'junit:junit:4.13-beta-3'
            androidTestİmplementation 'androidx.test:runner:1.3.0-alpha01'
            androidTestİmplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha01'
            implementation 'androidx.legacy:legacy-support-v4:1.0.0'
            implementation 'androidx.legacy:legacy-support-v13:1.0.0'

return requestfragment;請求片段出現錯誤return requestfragment; 我該如何解決?

查看requestfragment中的import

代替

import android.app.fragment

import androidx.fragment.app.Fragment

或者

android.support.v4.app.Fragment

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM