android.view.InflateException:二进制XML文件行#22:错误膨胀类com.google.ar.sceneform.ArSceneView

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (26)

我将Ar集成到我的Android项目中但是有一个我无法解决的错误:

我要将Ar集成到我的Android项目中,但是有一个我无法解决的错误:

Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class com.google.ar.sceneform.ArSceneView"
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.user.myapplication/com.example.user.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #22: Error inflating class com.google.ar.sceneform.ArSceneView
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2429)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
        at android.app.ActivityThread.access$800(ActivityThread.java:166)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5584)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
        at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class com.google.ar.sceneform.ArSceneView
        at android.view.LayoutInflater.createView(LayoutInflater.java:627)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:703)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:762)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
        at com.google.ar.sceneform.ux.BaseArFragment.onCreateView(BaseArFragment.java:137)
        at android.support.v4.app.Fragment.performCreateView(Fragment.java:2346)
        at android.support.v4.app.FragmentManagerImpl.ensureInflatedFragmentView(FragmentManager.java:1664)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1399)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1659)
        at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1905)
        at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3715)
        at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:114)
        at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:374)
        at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39)
        at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:68)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:762)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
        at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
        at com.example.user.myapplication.MainActivity.onCreate(MainActivity.java:25)
page .xml 
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context=".MainActivity">

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

</RelativeLayout>
public class MainActivity extends AppCompatActivity {
private ArFragment arFragment ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    arFragment= (ArFragment) getSupportFragmentManager().findFragmentById(R.id.fragment);
    arFragment.setOnTapArPlaneListener(new BaseArFragment.OnTapArPlaneListener() {
        @RequiresApi(api = Build.VERSION_CODES.N)
        @Override
        public void onTapPlane(HitResult hitResult, Plane plane, MotionEvent motionEvent) {
            Anchor anchor =hitResult.createAnchor();
            ModelRenderable.builder().setSource(MainActivity.this, Uri.parse("model.sfb")).build().thenAccept(modelRenderable -> addLr(anchor,modelRenderable))
                    .exceptionally((Throwable throwable) -> {
                        AlertDialog.Builder builder=new AlertDialog.Builder(MainActivity.this);
                        builder.setMessage(throwable.getMessage()).show();
                        return  null ;

                    });
        }
    });
    }



 private void addLr(Anchor anchor, ModelRenderable modelRenderable) {
        AnchorNode anchorNode= new AnchorNode(anchor);
        TransformableNode transformableNode=new TransformableNode(arFragment.getTransformationSystem());
                transformableNode.setParent(anchorNode);
                transformableNode.setRenderable(modelRenderable);
                arFragment.getArSceneView().getScene().addChild(anchorNode);
                transformableNode.select();
    }
}
提问于
用户回答回答于

你在gradle app依赖项中添加了库吗?

   implementation "com.google.ar.sceneform.ux:sceneform-ux:1.7.0"
用户回答回答于

扫码关注云+社区

领取腾讯云代金券