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

时间:2019-06-12 22:48:38

标签: android augmented-reality

J'ai vais integre ar en mon projet安卓系统可能无法正常运行:

我将把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();
    }
}

2 个答案:

答案 0 :(得分:0)

您是否在gradle应用程序依赖项中添加了库?

   implementation "com.google.ar.sceneform.ux:sceneform-ux:1.7.0"

答案 1 :(得分:0)

一个可行的解决方案

当我使用不同的场景形式库时出现此错误

implementation "com.google.ar.sceneform.ux:sceneform-ux:1.10.0"
implementation "com.google.ar.sceneform:animation:1.8.0"

请参见v10和v8一起使用。

implementation "com.google.ar.sceneform.ux:sceneform-ux:1.10.0"
implementation "com.google.ar.sceneform:animation:1.10.0"

已更新为相同版本!错误现在消失了!