R
R
Rustam2021-04-17 21:02:30
Android
Rustam, 2021-04-17 21:02:30

How to fix error with "androidx.fragment.app.Fragment"?

How to fix "androidx.fragment.app.Fragment cannot be converted to android.app.Fragment" error?
Due to my level of knowledge of Android studio, I do not understand how to solve this problem.
Please help.
607b2209b36c6419700911.png
607b229fee865030588313.png

package com.example.fragmentsrustamseipyshev;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.annotation.SuppressLint;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;


public class MainActivity extends AppCompatActivity {

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

    @SuppressLint("NonConstantResourceId")
    public void Change (View view){
        Fragment fragment = null;

        switch (view.getId()){
            case R.id.button:
                fragment = new Fragment1();
                break;

            case R.id.button1:
                fragment = new Fragment2();
                break;
        }

        FragmentManager fm = getFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.fr_place, fragment);
        ft.commit();
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2021-04-17
@santanaa

migrate to x to the end
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
Namely, for the fragment from the question
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question