本文介绍了无法访问getSupportFragmentManager()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.net.Uri;
import android.view.Gravity;
import android.view.MotionEvent;
import android.widget.ImageButton;
import android.widget.Toast;
import com.google.ar.core.Anchor;
import com.google.ar.core.HitResult;
import com.google.ar.core.Plane;
import com.google.ar.sceneform.AnchorNode;
import com.google.ar.sceneform.rendering.ModelRenderable;
import com.google.ar.sceneform.ux.ArFragment;
import com.google.ar.sceneform.ux.BaseArFragment;
import com.google.ar.sceneform.ux.TransformableNode;
import com.google.ar.sceneform.math.Quaternion;
import com.google.ar.sceneform.math.Vector3;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    private ArFragment arFragment;
    private ModelRenderable modelRenderable;

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

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

遇到错误:

Inconvertible types; cannot cast 'androidx.fragment.app.Fragment' to 'com.google.ar.sceneform.ux.ArFragment'

我已经为片段添加了导入吗?

I have add the import for fragment?

  1. 还在构建期间给出此错误.

  1. Also giving this Error during Build.

sceneformsrc \ sceneform \ src \ main \ java \ com \ google \ ar \ sceneform \ AnchorNode.java:3:错误:包android.support.annotation不存在导入android.support.annotation.Nullable;

sceneformsrc\sceneform\src\main\java\com\google\ar\sceneform\AnchorNode.java:3: error: package android.support.annotation does not existimport android.support.annotation.Nullable;

我遗漏了一些我得到这些错误的东西吗?

am missing something that I am getting these errors?

我正在使用Sceneform 1.16和Andriod studio 4.1

I am using Sceneform 1.16 and Andriod studio 4.1

推荐答案

<fragment
        android:id="@+id/face_fragment"
        android:name="com.google.ar.sceneform.ux.ArFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

您是否提到了android:name标签?

Have you mentioned the android:name tag?

这篇关于无法访问getSupportFragmentManager()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 19:52