如何解决不兼容的类型?

时间:2019-05-12 10:39:36

标签: android

我实际上是android studio的新手,现在我陷入了这个编译错误。请帮忙.. 以下是问题 FragmentActivity activity = this(); 显示编译错误

不兼容的类型

必需:androidx.fragment.app.FragmentActivity

找到:com.example.androidapp.MainActivity

我用过getSupportFragementManager()getFragementManager() ..这些都没有。.

相关代码

package com.example.androidapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import androidx.biometric.BiometricPrompt;
import android.os.Bundle;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import androidx.fragment.app.FragmentActivity;
import android.util.Log;
import android.view.View;
import androidx.annotation.NonNull;

   public class MainActivity extends AppCompatActivity {

    private static final String TAG = MainActivity.class.getName();

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

//Create a thread pool with a single thread//

        Executor newExecutor = Executors.newSingleThreadExecutor();

        FragmentActivity activity = this;

//Start listening for authentication events//

        final BiometricPrompt myBiometricPrompt = new BiometricPrompt(activity, newExecutor, new BiometricPrompt.AuthenticationCallback() {
           ...

1 个答案:

答案 0 :(得分:0)

更改导入和签名:

// import android.support.v7.app.AppCompatActivity;
import androidx.fragment.app.FragmentActivity;

public class MainActivity extends FragmentActivity {
    ...
}

另请参见Migrating to AndroidX了解更多替换软件包...

因为将android.supportandroidx混淆是有问题的。