启动新碎片

时间:2016-11-27 06:52:21

标签: android

我尝试让我的StartActivity课程可以从一个Fragment动态更改为另一个LoginFragment,例如首先它会打开StartAcitivity.class。如果用户没有任何帐户,他们可以注册新帐户。登录和注册将是一个活动中的两个不同的片段。

这是public class StartActivity extends AppCompatActivity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_start); if (savedInstanceState == null) { getSupportFragmentManager() .beginTransaction() .add(R.id.flDetailContainer, new LoginFragment(), "LOGIN") .commit(); } } }

LoginFragment.class

我的public class LoginFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_login, parent, false); } }

activity_start.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/flDetailContainer" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin"> </FrameLayout> 布局

fragment_login.xml

我的<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> </LinearLayout> 布局

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.example.asus.carclubapps, PID: 2748
                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.asus.carclubapps/com.example.asus.carclubapps.StartActivity}: java.lang.IllegalArgumentException: No view found for id 0x7f0c006f (com.example.asus.carclubapps:id/activity_start) for fragment RegistrationFragment{85ef24b #0 id=0x7f0c006f}
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                      at android.app.ActivityThread.-wrap11(ActivityThread.java)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:148)
                      at android.app.ActivityThread.main(ActivityThread.java:5417)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                   Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f0c006f (com.example.asus.carclubapps:id/activity_start) for fragment RegistrationFragment{85ef24b #0 id=0x7f0c006f}
                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1098)
                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1286)
                      at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:758)
                      at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1671)
                      at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:388)
                      at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:619)
                      at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1237)
                      at android.app.Activity.performStart(Activity.java:6253)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                      at android.os.Looper.loop(Looper.java:148) 
                      at android.app.ActivityThread.main(ActivityThread.java:5417) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

我得到的错误。

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by Asus on 11/27/2016.
 */

public class RegistrationFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_registration, parent, false);
    }
}

我确实有RegistrationFragment和fragment_registration,但是我的StartActivity上的东西我只调用了LoginFragment而不是RegistrationFragment。我在这里错过了什么吗?

RegistrationFragment

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    <TextView
        android:gravity="center_horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/title_registration"/>

</LinearLayout>

fragment_registration

public class MainActivity extends Activity {
private static final String TAG = MainActivity.class.getSimpleName();

private static final double UPDATE_INTERVAL_MS = 100.0;

private final Object mSharedLock = new Object();
// private static final String sTimestampFormat = "Timestamp: %f";
private static final int SECS_TO_MILLISECS = 1000;
private double mPreviousPoseTimeStamp;
private double mTimeToNextUpdate = UPDATE_INTERVAL_MS;
private TextView mUuidTextView;
private TextView mRelocalizationTextView;
private boolean mIsRelocalized;
private EditText mObjectValueEditText;
private Button mSaveButton;
private boolean mIsLocationSave = false;
private boolean mIsSavePoseData = false;
private static final int INVALID_TEXTURE_ID = 0;
private RajawaliSurfaceView mSurfaceView;
private VideoRenderer mRenderer;

// For all current Tango devices, color camera is in the camera id 0.
private static final int COLOR_CAMERA_ID = 0;

private TangoCameraIntrinsics mIntrinsics;
private Tango mTango;
private TangoConfig mConfig;
private boolean mIsConnected = false;
private double mCameraPoseTimestamp = 0;

// NOTE: Naming indicates which thread is in charge of updating this variable
private int mConnectedTextureIdGlThread = INVALID_TEXTURE_ID;
private AtomicBoolean mIsFrameAvailableTangoThread = new AtomicBoolean(false);
private double mRgbTimestampGlThread;

private int mColorCameraToDisplayAndroidRotation = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    startActivityForResult(
            Tango.getRequestPermissionIntent(Tango.PERMISSIONTYPE_ADF_LOAD_SAVE),
            Tango.TANGO_INTENT_ACTIVITYCODE);
    mSurfaceView = (RajawaliSurfaceView) findViewById(R.id.surfaceview);
    mObjectValueEditText = (EditText) findViewById(R.id.location_edittext);
    mSaveButton = (Button) findViewById(R.id.save_button);
    mRenderer = new VideoRenderer(this);
    onClickSaveButton();
    // Set-up a dummy OpenGL renderer associated with this surface view
    DisplayManager displayManager = (DisplayManager) getSystemService(DISPLAY_SERVICE);
    if (displayManager != null) {
        displayManager.registerDisplayListener(new DisplayManager.DisplayListener() {
            @Override
            public void onDisplayAdded(int displayId) {}

            @Override
            public void onDisplayChanged(int displayId) {
                synchronized (this) {
                    Display display = getWindowManager().getDefaultDisplay();
                    Camera.CameraInfo colorCameraInfo = new Camera.CameraInfo();
                    Camera.getCameraInfo(COLOR_CAMERA_ID, colorCameraInfo);

                    mColorCameraToDisplayAndroidRotation =
                            getColorCameraToDisplayAndroidRotation(display.getRotation(),
                                    colorCameraInfo.orientation);
                    mRenderer.updateColorCameraTextureUv(mColorCameraToDisplayAndroidRotation);
                }
            }

            @Override
            public void onDisplayRemoved(int displayId) {}
        }, null);
    }

    setupRenderer();
}

private void onClickSaveButton() {
    mSaveButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mIsLocationSave == false) {
                mIsLocationSave = true;
                mObjectValueEditText.setVisibility(View.VISIBLE);
                mSaveButton.setText(getResources().getString(R.string.save_object));
            } else {
                mIsLocationSave = false;
                String text=mObjectValueEditText.getText().toString();
                Toast.makeText(getApplicationContext(),text,Toast.LENGTH_SHORT).show();
                mObjectValueEditText.setVisibility(View.INVISIBLE);
                //TODO:Add helper logic
                mIsSavePoseData=true;
                mSaveButton.setText(getResources().getString(R.string.save));
            }
        }
    });
}

@Override
protected void onResume() {
    super.onResume();
    mSurfaceView.onResume();
    // Set render mode to RENDERMODE_CONTINUOUSLY to force getting onDraw callbacks until the
    // Tango service is properly set-up and we start getting onFrameAvailable callbacks.
    mSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);

    // Initialize Tango Service as a normal Android Service, since we call mTango.disconnect()
    // in onPause, this will unbind Tango Service, so every time when onResume gets called, we
    // should create a new Tango object.
    mTango = new Tango(MainActivity.this, new Runnable() {
        // Pass in a Runnable to be called from UI thread when Tango is ready, this Runnable
        // will be running on a new thread.
        // When Tango is ready, we can call Tango functions safely here only when there is no UI
        // thread changes involved.
        @Override
        public void run() {
            // Synchronize against disconnecting while the service is being used in
            // the OpenGL thread or in the UI thread.
            synchronized (MainActivity.this) {
                try {
                    TangoSupport.initialize();
                    mConfig = setupTangoConfig(mTango);
                    mTango.connect(mConfig);
                    startupTango();
                    mIsConnected = true;
                } catch (TangoOutOfDateException e) {
                    Log.e(TAG, getString(R.string.exception_out_of_date), e);
                } catch (TangoErrorException e) {
                    Log.e(TAG, getString(R.string.exception_tango_error), e);
                } catch (TangoInvalidException e) {
                    Log.e(TAG, getString(R.string.exception_tango_invalid), e);
                }

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        synchronized (MainActivity.this) {
                            setupTextViewsAndButtons(mTango, true,
                                    true);
                        }
                    }
                });
            }
        }
    });


}

@Override
protected void onPause() {
    super.onPause();
    mSurfaceView.onPause();
    mIsRelocalized = false;
    // Synchronize against disconnecting while the service is being used in the OpenGL
    // thread or in the UI thread.
    // NOTE: DO NOT lock against this same object in the Tango callback thread.
    // Tango.disconnect will block here until all Tango callback calls are finished.
    // If you lock against this object in a Tango callback thread it will cause a deadlock.
    synchronized (this) {
        try {
            mIsConnected = false;
            mTango.disconnectCamera(TangoCameraIntrinsics.TANGO_CAMERA_COLOR);
            // We need to invalidate the connected texture ID so that we cause a
            // re-connection in the OpenGL thread after resume
            mConnectedTextureIdGlThread = INVALID_TEXTURE_ID;
            mTango.disconnect();
            mIsConnected = false;
        } catch (TangoErrorException e) {
            Log.e(TAG, getString(R.string.exception_tango_error), e);
        }
    }
}

/**
 * Sets up the tango configuration object. Make sure mTango object is initialized before
 * making this call.
 */
private TangoConfig setupTangoConfig(Tango tango) {
    // Create a new Tango Configuration and enable the Camera API
    TangoConfig config = tango.getConfig(TangoConfig.CONFIG_TYPE_DEFAULT);
    config.putBoolean(TangoConfig.KEY_BOOLEAN_COLORCAMERA, true);
    config.putBoolean(TangoConfig.KEY_BOOLEAN_DRIFT_CORRECTION, true);
    config.putBoolean(TangoConfig.KEY_BOOLEAN_LOWLATENCYIMUINTEGRATION, true);
    config.putBoolean(TangoConfig.KEY_BOOLEAN_LEARNINGMODE, false);
    config.putBoolean(TangoConfig.KEY_BOOLEAN_MOTIONTRACKING, true);
    // Tango service should automatically attempt to recover when it enters an invalid state.
    config.putBoolean(TangoConfig.KEY_BOOLEAN_AUTORECOVERY, true);

    // Check for Load ADF/Constant Space relocalization mode.

    ArrayList<String> fullUuidList;
    // Returns a list of ADFs with their UUIDs.
    fullUuidList = tango.listAreaDescriptions();
    // Load the latest ADF if ADFs are found.
    if (fullUuidList.size() > 0) {
        config.putString(TangoConfig.KEY_STRING_AREADESCRIPTION,
                fullUuidList.get(fullUuidList.size() - 1));
    }

    return config;
}

/**
 * Set up the callback listeners for the Tango service and obtain other parameters required
 * after Tango connection.
 * Listen to updates from the RGB camera.
 */
private void startupTango() {
    // Lock configuration and connect to Tango
    // Select coordinate frame pair
    ArrayList<TangoCoordinateFramePair> framePairs = new ArrayList<TangoCoordinateFramePair>();
    framePairs.add(new TangoCoordinateFramePair(
            TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
            TangoPoseData.COORDINATE_FRAME_DEVICE));
    framePairs.add(new TangoCoordinateFramePair(
            TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION,
            TangoPoseData.COORDINATE_FRAME_DEVICE));
    framePairs.add(new TangoCoordinateFramePair(
            TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION,
            TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE));


    // Listen for new Tango data
    mTango.connectListener(framePairs, new Tango.OnTangoUpdateListener() {
        @Override
        public void onPoseAvailable(final TangoPoseData pose) {
            // Make sure to have atomic access to Tango Data so that UI loop doesn't interfere
            // while Pose call back is updating the data.
            synchronized (mSharedLock) {
                // Check for Device wrt ADF pose, Device wrt Start of Service pose, Start of
                // Service wrt ADF pose (This pose determines if the device is relocalized or
                // not).
                if (pose.baseFrame == TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION
                        && pose.targetFrame == TangoPoseData
                        .COORDINATE_FRAME_START_OF_SERVICE) {
                    if (pose.statusCode == TangoPoseData.POSE_VALID) {
                        mIsRelocalized = true;
                    } else {
                        mIsRelocalized = false;
                    }

                }

                if (mIsSavePoseData&&mIsRelocalized) {
                    mIsSavePoseData=false;
                    float [] traslations=pose.getTranslationAsFloats();
                    Log.i("translation",traslations[0]+" "+traslations[1]+" "+traslations[2]);

                }

            }

            final double deltaTime = (pose.timestamp - mPreviousPoseTimeStamp) *
                    SECS_TO_MILLISECS;
            mPreviousPoseTimeStamp = pose.timestamp;
            mTimeToNextUpdate -= deltaTime;

            if (mTimeToNextUpdate < 0.0) {
                mTimeToNextUpdate = UPDATE_INTERVAL_MS;

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        synchronized (mSharedLock) {
                            mRelocalizationTextView.setText(mIsRelocalized ?
                                    getString(R.string.localized) :
                                    getString(R.string.not_localized));
                        }
                    }
                });
            }
        }

        //Deprecated method
        @Override
        public void onXyzIjAvailable(TangoXyzIjData xyzIj) {
            // We are not using onXyzIjAvailable for this app.
        }

        @Override
        public void onPointCloudAvailable(final TangoPointCloudData pointCloudData) {

        }

        @Override
        public void onTangoEvent(final TangoEvent event) {

        }

        @Override
        public void onFrameAvailable(int cameraId) {
            Log.d(TAG, "onFrameAvailable");

            if (cameraId == TangoCameraIntrinsics.TANGO_CAMERA_COLOR) {
                // Now that we are receiving onFrameAvailable callbacks, we can switch
                // to RENDERMODE_WHEN_DIRTY to drive the render loop from this callback.
                // This will result on a frame rate of  approximately 30FPS, in synchrony with
                // the RGB camera driver.
                // If you need to render at a higher rate (i.e.: if you want to render complex
                // animations smoothly) you  can use RENDERMODE_CONTINUOUSLY throughout the
                // application lifecycle.
                if (mSurfaceView.getRenderMode() != GLSurfaceView.RENDERMODE_WHEN_DIRTY) {
                    mSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
                }

                mSurfaceView.requestRender();
            }
        }
    });
}

/**
 * Sets Texts views to display statistics of Poses being received. This also sets the buttons
 * used in the UI. Please note that this needs to be called after TangoService and Config
 * objects are initialized since we use them for the SDK related stuff like version number
 * etc.
 */
private void setupTextViewsAndButtons(Tango tango, boolean isLearningMode, boolean isLoadAdf) {
    mRelocalizationTextView = (TextView) findViewById(R.id.relocalization_textview);
    mUuidTextView = (TextView) findViewById(R.id.adf_uuid_textview);

    if (isLoadAdf) {
        ArrayList<String> fullUuidList;
        // Returns a list of ADFs with their UUIDs
        fullUuidList = tango.listAreaDescriptions();
        if (fullUuidList.size() == 0) {
            mUuidTextView.setText(R.string.no_uuid);
        } else {
            mUuidTextView.setText(getString(R.string.number_of_adfs) + fullUuidList.size()
                    + getString(R.string.latest_adf_is)
                    + fullUuidList.get(fullUuidList.size() - 1));
        }
    }
}


/**
 * Here is where you would set-up your rendering logic. We're replacing it with a minimalistic,
 * dummy example using a standard GLSurfaceView and a basic renderer, for illustration purposes
 * only.
 */
private void setupRenderer() {

    mRenderer.getCurrentScene().registerFrameCallback(new ASceneFrameCallback() {
        @Override
        public void onPreFrame(long sceneTime, double deltaTime) {

            // into the scene.

            // Prevent concurrent access to {@code mIsFrameAvailableTangoThread} from the Tango
            // callback thread and service disconnection from an onPause event.
            try {
                synchronized (MainActivity.this) {
                    // Don't execute any tango API actions if we're not connected to the service
                    if (!mIsConnected) {
                        return;
                    }

                    // Set-up scene camera projection to match RGB camera intrinsics.
                    if (!mRenderer.isSceneCameraConfigured()) {
                        mRenderer.setProjectionMatrix(
                                projectionMatrixFromCameraIntrinsics(mIntrinsics,
                                        mColorCameraToDisplayAndroidRotation));
                    }
                    // Connect the camera texture to the OpenGL Texture if necessary
                    // NOTE: When the OpenGL context is recycled, Rajawali may re-generate the
                    // texture with a different ID.
                    if (mConnectedTextureIdGlThread != mRenderer.getTextureId()) {
                        mTango.connectTextureId(TangoCameraIntrinsics.TANGO_CAMERA_COLOR,
                                mRenderer.getTextureId());
                        mConnectedTextureIdGlThread = mRenderer.getTextureId();
                        Log.d(TAG, "connected to texture id: " + mRenderer.getTextureId());
                    }
                    if (mIsFrameAvailableTangoThread.compareAndSet(true, false)) {
                        mRgbTimestampGlThread =
                                mTango.updateTexture(TangoCameraIntrinsics.TANGO_CAMERA_COLOR);
                    }

                    // If a new RGB frame has been rendered, update the camera pose to match.
                    if (mRgbTimestampGlThread > mCameraPoseTimestamp) {
                        // Calculate the camera color pose at the camera frame update time in
                        // OpenGL engine.
                        //
                        // When drift correction mode is enabled in config file, we must query
                        // the device with respect to Area Description pose in order to use the
                        // drift corrected pose.
                        //
                        // Note that if you don't want to use the drift corrected pose, the
                        // normal device with respect to start of service pose is available.
                        TangoPoseData lastFramePose = TangoSupport.getPoseAtTime(
                                mRgbTimestampGlThread,
                                TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION,
                                TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR,
                                TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL,
                                mColorCameraToDisplayAndroidRotation);
                        if (lastFramePose.statusCode == TangoPoseData.POSE_VALID) {
                            // Update the camera pose from the renderer
                            mRenderer.updateRenderCameraPose(lastFramePose);
                            mCameraPoseTimestamp = lastFramePose.timestamp;
                        } else {
                            // When the pose status is not valid, it indicates the tracking has
                            // been lost. In this case, we simply stop rendering.
                            //
                            // This is also the place to display UI to suggest the user walk
                            // to recover tracking.
                            Log.w(TAG, "Can't get device pose at time: " +
                                    mRgbTimestampGlThread);
                        }
                    }
                }

                // Avoid crashing the application due to unhandled exceptions
            } catch (TangoErrorException e) {
                Log.e(TAG, "Tango API call error within the OpenGL render thread", e);
            } catch (Throwable t) {
                Log.e(TAG, "Exception on the OpenGL thread", t);
            }
        }

        @Override
        public void onPreDraw(long sceneTime, double deltaTime) {

        }

        @Override
        public void onPostFrame(long sceneTime, double deltaTime) {

        }

        @Override
        public boolean callPreFrame() {
            return true;
        }
    });

    mSurfaceView.setSurfaceRenderer(mRenderer);

}

private static int getColorCameraToDisplayAndroidRotation(int displayRotation,
                                                          int cameraRotation) {
    int cameraRotationNormalized = 0;
    switch (cameraRotation) {
        case 90:
            cameraRotationNormalized = 1;
            break;
        case 180:
            cameraRotationNormalized = 2;
            break;
        case 270:
            cameraRotationNormalized = 3;
            break;
        default:
            cameraRotationNormalized = 0;
            break;
    }
    int ret = displayRotation - cameraRotationNormalized;
    if (ret < 0) {
        ret += 4;
    }
    return ret;
}

/**
 * Use Tango camera intrinsics to calculate the projection Matrix for the Rajawali scene.

private static float[] projectionMatrixFromCameraIntrinsics(TangoCameraIntrinsics intrinsics,
                                                            int rotation) {
    // Adjust camera intrinsics according to rotation
    float cx = (float) intrinsics.cx;
    float cy = (float) intrinsics.cy;
    float width = (float) intrinsics.width;
    float height = (float) intrinsics.height;
    float fx = (float) intrinsics.fx;
    float fy = (float) intrinsics.fy;

    switch (rotation) {
        case Surface.ROTATION_90:
            cx = (float) intrinsics.cy;
            cy = (float) intrinsics.width - (float) intrinsics.cx;
            width = (float) intrinsics.height;
            height = (float) intrinsics.width;
            fx = (float) intrinsics.fy;
            fy = (float) intrinsics.fx;
            break;
        case Surface.ROTATION_180:
            cx = (float) intrinsics.width - cx;
            cy = (float) intrinsics.height - cy;
            break;
        case Surface.ROTATION_270:
            cx = (float) intrinsics.height - (float) intrinsics.cy;
            cy = (float) intrinsics.cx;
            width = (float) intrinsics.height;
            height = (float) intrinsics.width;
            fx = (float) intrinsics.fy;
            fy = (float) intrinsics.fx;
            break;
        default:
            break;
    }

    // Uses frustumM to create a projection matrix taking into account calibrated camera
    // intrinsic parameter.
    // Reference: http://ksimek.github.io/2013/06/03/calibrated_cameras_in_opengl/
    float near = 0.1f;
    float far = 100;

    float xScale = near / fx;
    float yScale = near / fy;
    float xOffset = (cx - (width / 2.0f)) * xScale;
    // Color camera's coordinates has y pointing downwards so we negate this term.
    float yOffset = -(cy - (height / 2.0f)) * yScale;

    float m[] = new float[16];
    Matrix.frustumM(m, 0,
            xScale * (float) -width / 2.0f - xOffset,
            xScale * (float) width / 2.0f - xOffset,
            yScale * (float) -height / 2.0f - yOffset,
            yScale * (float) height / 2.0f - yOffset,
            near, far);
    return m;
}

3 个答案:

答案 0 :(得分:1)

logcat清楚地表明问题出在RegistrationFragment布局的activity_start.xml中。

No view found for id 0x7f0c006f (com.example.asus.carclubapps:id/activity_start) for fragment RegistrationFragment{85ef24b #0 id=0x7f0c006f}

它还表示您指的是activity_start.xml布局中不存在的无效视图。

这是您的activity_start.xml布局

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:id="@+id/flDetailContainer"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:paddingBottom="@dimen/activity_vertical_margin"
     android:paddingLeft="@dimen/activity_horizontal_margin"
     android:paddingRight="@dimen/activity_horizontal_margin"
     android:paddingTop="@dimen/activity_vertical_margin">

</FrameLayout>

我看到您可能不希望从FrameLayout获得一个flDetailContainer RegisterFragmentRegisterFragment。我认为您在LayoutInflater内部使用fragment_register.xml从布局中获取视图时出现错误视图。

我猜,有一个名为RegisterFragment的布局。您需要在onCreateView中获取该布局的视图。

在这种情况下,RegisterFragment的{​​{1}}功能可能看起来像

public class RegisterFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_register, parent, false);
    }
}

答案 1 :(得分:0)

RegistrationFragment 中的日志中,您正在尝试访问您附加的片段布局文件中实际不存在的视图。

请在 RegistrationFragment 中确认您附加了正确的观点。因为当您尝试使用当前附加视图实际上不存在的视图时,通常会出现错误(查看未找到)。

如果仍无效,请尝试使缓存无效并重新启动Android Studio。

答案 2 :(得分:0)

错误来自另一个Activity,主要是Registerfragment。视图不正确。

 Unable to start activity --> No view found for fragment RegistrationFragment

如果您修复了视图并且问题仍然存在,请及时更新我们,我们会及时解决。