Android Studio 是不兼容的androidx. fragment.app,

bcs8qyzn  于 2023-02-06  发布在  Android
关注(0)|答案(1)|浏览(178)

android studio不再支持sceneform库了吗?因为每当我用(ArFragment) getSupportFragmentManager().findFragmentById(R.id.fragment)示例化ArFragment时,我会得到一个错误消息,显示Inconvertible types; cannot cast 'androidx.fragment.app.Fragment' to 'com.google.ar.sceneform.ux.ArFragment
我已经把<meta-data android:name="com.google.ar.core" android:value="required" />和所有需要的东西放在清单上了
这是我的xml代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <fragment
        android:id="@+id/fragment"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:name="com.google.ar.sceneform.ux.ArFragment" />

</LinearLayout>

这是我的Java代码

package com.example.test;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.google.ar.sceneform.ux.ArFragment;

public class MainActivity extends AppCompatActivity {
    ArFragment arFragment;

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

        arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.fragment);
    }
}

这是我的gradle依赖项

implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    implementation 'com.google.ar.sceneform.ux:sceneform-ux:1.17.1'

相关问题