简体   繁体   中英

How to fix "Incompatible Types" error in Android Studio?

I am the beginner in Android studio and working on beginner project as a chat app. Working oc Fragment class there is a problem appeared :"Incompatible types"

I have tried other resolutions on the internet that i found but did not work.

Here is my class:

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;
    }
}

and here is my 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'

There is an error apperaing on return requestfragment; How can i fix it?

Have a look in the import in your requestfragment .

Replace

import android.app.fragment

with

import androidx.fragment.app.Fragment

or

android.support.v4.app.Fragment

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM