Ошибка при раздувании класса com.google.vrtoolkit.cardboard.CardboardView приводит к сбою приложения

у него нет ошибки сборки, но происходит сбой при запуске на эмуляторе.

основная деятельность

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myrajawali">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity" android:screenOrientation="landscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="com.google.intent.category.CARDBOARD" />
            </intent-filter>
        </activity>
    </application>

</manifest>

MainActivity.java

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black"
    tools:context=".MainActivity">

    <com.google.vrtoolkit.cardboard.CardboardView
        android:id="@+id/cardboard_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</RelativeLayout>

VedioRenderer.java

    package com.example.myrajawali;



import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;


import com.google.vrtoolkit.cardboard.CardboardActivity;
import com.google.vrtoolkit.cardboard.CardboardView;



public class MainActivity extends CardboardActivity {

    private CardboardView cardboardView;
    private MediaPlayer mediaPlayer;

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

        cardboardView = findViewById(R.id.cardboard_view);

        // init media player for video
        mediaPlayer = MediaPlayer.create(this, R.raw.sample);
        Log.d("AAAA","aaaaaaaaaaaaaaaaaaaaaaaa");
        mediaPlayer.setLooping(true);

        //create renderee

        CardboardView.StereoRenderer renderer = new Vediorenderer(this, mediaPlayer);
        // associate a renderer with cardboardView
        cardboardView.setRenderer(renderer);

        // associate the cardboardView with this activity
        setCardboardView(cardboardView);

    }

    @Override
    public void onCardboardTrigger() {
        super.onCardboardTrigger();

        // toggle vr mode on touch/trigger
        cardboardView.setVRModeEnabled(!cardboardView.getVRMode());
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (mediaPlayer != null) {
            mediaPlayer.pause();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (mediaPlayer != null) {
            mediaPlayer.start();
        }
    }



}

Эта ошибка возникает, когда в вашем XML-файле макета есть какие-либо проблемы. Ошибка возникает в строке № 9 вашего

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black"
    tools:context=".MainActivity">

    <com.google.vrtoolkit.cardboard.CardboardView
        android:id="@+id/cardboard_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</RelativeLayout>
, где вы используете
    package com.example.myrajawali;



import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;


import com.google.vrtoolkit.cardboard.CardboardActivity;
import com.google.vrtoolkit.cardboard.CardboardView;



public class MainActivity extends CardboardActivity {

    private CardboardView cardboardView;
    private MediaPlayer mediaPlayer;

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

        cardboardView = findViewById(R.id.cardboard_view);

        // init media player for video
        mediaPlayer = MediaPlayer.create(this, R.raw.sample);
        Log.d("AAAA","aaaaaaaaaaaaaaaaaaaaaaaa");
        mediaPlayer.setLooping(true);

        //create renderee

        CardboardView.StereoRenderer renderer = new Vediorenderer(this, mediaPlayer);
        // associate a renderer with cardboardView
        cardboardView.setRenderer(renderer);

        // associate the cardboardView with this activity
        setCardboardView(cardboardView);

    }

    @Override
    public void onCardboardTrigger() {
        super.onCardboardTrigger();

        // toggle vr mode on touch/trigger
        cardboardView.setVRModeEnabled(!cardboardView.getVRMode());
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (mediaPlayer != null) {
            mediaPlayer.pause();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (mediaPlayer != null) {
            mediaPlayer.start();
        }
    }



}
из
package com.example.myrajawali;

import android.content.Context;
import android.graphics.SurfaceTexture;
import android.media.MediaPlayer;
import android.view.MotionEvent;

import com.google.vrtoolkit.cardboard.CardboardView;
import com.google.vrtoolkit.cardboard.Eye;
import com.google.vrtoolkit.cardboard.FieldOfView;
import com.google.vrtoolkit.cardboard.HeadTransform;
import com.google.vrtoolkit.cardboard.Viewport;

import org.rajawali3d.cameras.Camera;
import org.rajawali3d.materials.Material;
import org.rajawali3d.math.Matrix4;
import org.rajawali3d.math.Quaternion;
import org.rajawali3d.math.vector.Vector3;
import org.rajawali3d.primitives.Sphere;
import org.rajawali3d.renderer.Renderer;

import javax.microedition.khronos.egl.EGLConfig;

import c.org.rajawali3d.textures.StreamingTexture;
 //import rajawali.renderer.RajawaliRenderer;



public class Vediorenderer extends Renderer implements CardboardView.StereoRenderer {
    // video stuff
    private MediaPlayer mediaPlayer;
    private StreamingTexture videoTexture;

    // temporary math variables
    /** position and rotation of eye camera in 3d space as matrix object */
    private Matrix4 eyeMatrix;
    /** rotation of eye camera in 3d space */
    private Quaternion eyeOrientation;
    /** position of eye camera in 3d space */
    private Vector3 eyePosition;


    /**
     * @param context      e.g. an activity
     * @param mediaPlayer  Fully initialized media player instance with loaded video.
     *                     Make sure to call play/pause by yourself.
     */
    public  Vediorenderer(Context context, MediaPlayer mediaPlayer){
        super(context);
        this.mediaPlayer = mediaPlayer;
        // init math stuff
        eyeMatrix = new Matrix4();
        eyeOrientation = new Quaternion();
    }

    /*========================================================
     Override Renderer abstract methods
     =========================================================*/

    @Override
    protected void initScene() {
        // setup world sphere
        Sphere sphere = new Sphere(1, 24, 24);
        sphere.setPosition(0, 0, 0);
        // invert the sphere normals
        // factor "1" is two small and result in rendering glitches
        sphere.setScaleX(100);
        sphere.setScaleY(100);
        sphere.setScaleZ(-100);
        // create texture from media player video
        videoTexture = new StreamingTexture("video", this.mediaPlayer);
        // set material with video texture
        Material material = new Material();
        material.setColorInfluence(0f);
        try {
            material.addTexture(videoTexture);
        } catch (Exception e){
            throw new RuntimeException(e);
        }
        sphere.setMaterial(material);

        // add sphere to scene
        getCurrentScene().addChild(sphere);
    }
    @Override
    public void onRenderSurfaceDestroyed(SurfaceTexture surfaceTexture) {
        super.onRenderSurfaceDestroyed(surfaceTexture);
        mediaPlayer.stop();
        mediaPlayer.release();
    }
    @Override
    public void onOffsetsChanged(float xOffset, float yOffset, float xOffsetStep, float yOffsetStep, int xPixelOffset, int yPixelOffset) {

    }

    @Override
    public void onTouchEvent(MotionEvent event) {

    }

    /*========================================================
     Override CarboardView abstract methods
     =========================================================*/



    @Override
    public void onNewFrame(HeadTransform headTransform) {

    }

    @Override
    public void onDrawEye(Eye eye) {
        // Rajawali camera
        Camera currentCamera = getCurrentCamera();

        // cardboard field of view
        FieldOfView fov = eye.getFov();

        // update Rajawali camera from cardboard sdk
        currentCamera.updatePerspective(fov.getLeft(), fov.getRight(), fov.getBottom(), fov.getTop());
        eyeMatrix.setAll(eye.getEyeView());
        // orientation
        eyeOrientation.fromMatrix(eyeMatrix);
        currentCamera.setOrientation(eyeOrientation);
        // position
        eyePosition = eyeMatrix.getTranslation().inverse();
        currentCamera.setPosition(eyePosition);

        // render with Rajawali
        super.onRenderFrame(null);
    }

    @Override
    public void onFinishFrame(Viewport viewport) {

    }

    @Override
    public void onSurfaceChanged(int width, int height) {
        // tell Rajawali that cardboard sdk detected a size change
        super.onRenderSurfaceSizeChanged(null, width, height);
    }


    @Override
    public void onSurfaceCreated(EGLConfig eglConfig) {
        // pass opengl config to Rajawali
        super.onRenderSurfaceCreated(eglConfig, null, -1, -1);
    }

    @Override
    public void onRendererShutdown() {
        // tell Rajawali about shutdown
        super.onRenderSurfaceDestroyed(null);
    }
    @Override
    protected void onRender(long elapsedRealTime, double deltaTime) {
        super.onRender(elapsedRealTime, deltaTime);

        if (videoTexture != null) {
            // update texture from video content
            videoTexture.update();
        }
    }

}
.

package com.example.myrajawali;

import android.content.Context;
import android.graphics.SurfaceTexture;
import android.media.MediaPlayer;
import android.view.MotionEvent;

import com.google.vrtoolkit.cardboard.CardboardView;
import com.google.vrtoolkit.cardboard.Eye;
import com.google.vrtoolkit.cardboard.FieldOfView;
import com.google.vrtoolkit.cardboard.HeadTransform;
import com.google.vrtoolkit.cardboard.Viewport;

import org.rajawali3d.cameras.Camera;
import org.rajawali3d.materials.Material;
import org.rajawali3d.math.Matrix4;
import org.rajawali3d.math.Quaternion;
import org.rajawali3d.math.vector.Vector3;
import org.rajawali3d.primitives.Sphere;
import org.rajawali3d.renderer.Renderer;

import javax.microedition.khronos.egl.EGLConfig;

import c.org.rajawali3d.textures.StreamingTexture;
 //import rajawali.renderer.RajawaliRenderer;



public class Vediorenderer extends Renderer implements CardboardView.StereoRenderer {
    // video stuff
    private MediaPlayer mediaPlayer;
    private StreamingTexture videoTexture;

    // temporary math variables
    /** position and rotation of eye camera in 3d space as matrix object */
    private Matrix4 eyeMatrix;
    /** rotation of eye camera in 3d space */
    private Quaternion eyeOrientation;
    /** position of eye camera in 3d space */
    private Vector3 eyePosition;


    /**
     * @param context      e.g. an activity
     * @param mediaPlayer  Fully initialized media player instance with loaded video.
     *                     Make sure to call play/pause by yourself.
     */
    public  Vediorenderer(Context context, MediaPlayer mediaPlayer){
        super(context);
        this.mediaPlayer = mediaPlayer;
        // init math stuff
        eyeMatrix = new Matrix4();
        eyeOrientation = new Quaternion();
    }

    /*========================================================
     Override Renderer abstract methods
     =========================================================*/

    @Override
    protected void initScene() {
        // setup world sphere
        Sphere sphere = new Sphere(1, 24, 24);
        sphere.setPosition(0, 0, 0);
        // invert the sphere normals
        // factor "1" is two small and result in rendering glitches
        sphere.setScaleX(100);
        sphere.setScaleY(100);
        sphere.setScaleZ(-100);
        // create texture from media player video
        videoTexture = new StreamingTexture("video", this.mediaPlayer);
        // set material with video texture
        Material material = new Material();
        material.setColorInfluence(0f);
        try {
            material.addTexture(videoTexture);
        } catch (Exception e){
            throw new RuntimeException(e);
        }
        sphere.setMaterial(material);

        // add sphere to scene
        getCurrentScene().addChild(sphere);
    }
    @Override
    public void onRenderSurfaceDestroyed(SurfaceTexture surfaceTexture) {
        super.onRenderSurfaceDestroyed(surfaceTexture);
        mediaPlayer.stop();
        mediaPlayer.release();
    }
    @Override
    public void onOffsetsChanged(float xOffset, float yOffset, float xOffsetStep, float yOffsetStep, int xPixelOffset, int yPixelOffset) {

    }

    @Override
    public void onTouchEvent(MotionEvent event) {

    }

    /*========================================================
     Override CarboardView abstract methods
     =========================================================*/



    @Override
    public void onNewFrame(HeadTransform headTransform) {

    }

    @Override
    public void onDrawEye(Eye eye) {
        // Rajawali camera
        Camera currentCamera = getCurrentCamera();

        // cardboard field of view
        FieldOfView fov = eye.getFov();

        // update Rajawali camera from cardboard sdk
        currentCamera.updatePerspective(fov.getLeft(), fov.getRight(), fov.getBottom(), fov.getTop());
        eyeMatrix.setAll(eye.getEyeView());
        // orientation
        eyeOrientation.fromMatrix(eyeMatrix);
        currentCamera.setOrientation(eyeOrientation);
        // position
        eyePosition = eyeMatrix.getTranslation().inverse();
        currentCamera.setPosition(eyePosition);

        // render with Rajawali
        super.onRenderFrame(null);
    }

    @Override
    public void onFinishFrame(Viewport viewport) {

    }

    @Override
    public void onSurfaceChanged(int width, int height) {
        // tell Rajawali that cardboard sdk detected a size change
        super.onRenderSurfaceSizeChanged(null, width, height);
    }


    @Override
    public void onSurfaceCreated(EGLConfig eglConfig) {
        // pass opengl config to Rajawali
        super.onRenderSurfaceCreated(eglConfig, null, -1, -1);
    }

    @Override
    public void onRendererShutdown() {
        // tell Rajawali about shutdown
        super.onRenderSurfaceDestroyed(null);
    }
    @Override
    protected void onRender(long elapsedRealTime, double deltaTime) {
        super.onRender(elapsedRealTime, deltaTime);

        if (videoTexture != null) {
            // update texture from video content
            videoTexture.update();
        }
    }

}

person nagaxe    schedule 24.09.2019    source источник
comment
библиотека rajawali, внутренне расширяющая ее, если я попытаюсь добавить картонный sdk, обнаружится его бросающий повторяющийся класс   -  person axierjhtjz    schedule 24.09.2019
comment
--------- начало сбоя E / Android Runtime: FATAL EXCEPTION: main Process: com.example.myrajawali, PID: 6166 java.lang.RuntimeException: невозможно запустить активность ComponentInfo {com.example.myrajawali / com .example.myrajawali.MainActivity}: android.view.InflateException: строка # 9 двоичного файла XML в com.example.myrajawali: layout / activity_main: строка # 9 двоичного файла XML в com.example.myrajawali: layout / activity_main: Ошибка накачивания класс com.google.vrtoolkit.cardboard.CardboardView в android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3270) в android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3409) в android.app.servertransaction.LaunchActivityItem.exec (LaunchActivityItem.java:83) в android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:135) в android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:95) в android.app.ActivityThread $ H.handleMessage (ActivityThread.java:2016) в android.os.Handler.dispatchMessage (Handler.java:107) в android.os.Looper.loop (Looper.java:214) в android.app.ActivityThread.main ( ActivityThread.java:7356) на java.lang.reflect.Method.invoke (собственный метод) на com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run (RuntimeInit.java:492) на com.android.internal.os. ZygoteInit.main (ZygoteInit.java:930) Вызвано: android.view.InflateException: строка # 9 двоичного файла XML в com.example.myrajawali: layout / activity_main: строка # 9 двоичного файла XML в com.example.myrajawali: layout / activity_main: Ошибка при раздувании класса com.google.vrtoolkit.cardboard.CardboardView Причина: android.view.InflateException: строка № 9 двоичного файла XML в com.example.myrajawali: layout / activity_main: Ошибка при раздувании класса com.google.vrtoolkit. cardboard.CardboardView Вызвано: java.lang.reflect.InvocationTargetException в java.lang.reflect.Constructor.newIn stance0 (собственный метод) в java.lang.reflect.Constructor.newInstance (Constructor.java:343) в android.view.LayoutInflater.createView (LayoutInflater.java:854) в android.view.LayoutInflater.createViewFromTag (LayoutInflater.java: 1006) на android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:961) на android.view.LayoutInflater.rInflate (LayoutInflater.java:1123) на android.view.LayoutInflater.rInflateChildren (LayoutInflater) на android .:1084 Посмотреть. LayoutInflater.inflate (LayoutInflater.java:682) на android.view.LayoutInflater.inflate (LayoutInflater.java:534) на android.view.LayoutInflater.inflate (LayoutInflater.java:481) на com.android.internal.policy.PhoneWindow .setContentView (PhoneWindow.java:438) в android.app.Activity.setContentView (Activity.java:3324) в com.example.myrajawali.MainActivity.onCreate (MainActivity.java:23) в android.app.Activity.performCreate ( Activity.java:7802) в android.app.Activity.performCreate (Activity.java:7791) в android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1299) в android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3245 ) в android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3409) в android.app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem.java:83)   -  person nagaxe    schedule 24.09.2019


Ответы (1)


android.view.InflateException

Вероятность ошибки из-за того, что макет XML не раздувается должным образом для просмотра. Вы должны проверить, правильно ли добавлена ​​библиотека в build.gradle.

Также делайте Clean Project и Rebuild Project.

Кажется, не удается найти com.google.vrtoolkit.cardboard.CardboardView на вашем xml. У вас есть классы этого проекта (библиотеки или зависимости), добавленные в ваш проект?

person Muhammad Awais    schedule 24.09.2019