java.lang.IllegalArgumentException:找不到视图

时间:2016-09-17 19:11:12

标签: android layout view fragment illegalargumentexception

当我试图用另一个片段替换片段时,我收到了这条消息。这是我第一次尝试安卓,我希望你能帮助我。 这是错误消息:

                                                      java.lang.IllegalArgumentException: No view found for id 0x7f0d0083 (comtec.uks.de.jccapp:id/fragment_container) for fragment GradesFragment{1e6f8ce #0 id=0x7f0d0083}
                                                                    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1102)
                                                                    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1290)
                                                                    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)
                                                                    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1677)
                                                                    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:536)
                                                                    at android.os.Handler.handleCallback(Handler.java:739)
                                                                    at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                    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)

我有tablayout个不同的片段,在一个标签中,我想用Fragment A(GradesFragment)替换Fragment B(LoginFragment)。

以下是onActivityCreated中的onCreateViewFragment A方法:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    login_fragment = inflater.inflate(R.layout.fragment_login, container, false);
    return login_fragment;
}


@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mLoginView = (EditText) login_fragment.findViewById(R.id.login);
    mPasswordView = (EditText) login_fragment.findViewById(R.id.password);

    Button mEmailSignInButton = (Button) login_fragment.findViewById(R.id.email_sign_in_button);
    mEmailSignInButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            boolean valid;

            // Reset errors.
            mLoginView.setError(null);
            mPasswordView.setError(null);

            // Store values at the time of the login attempt.
            String username = mLoginView.getText().toString();
            String password = mPasswordView.getText().toString();

            valid = checkEmptyField(mLoginView) && checkEmptyField(mPasswordView);

            disableKeyboard();

            if (valid) {
                if (attemptLogin(username, password)) {

                    TransferDoc transferDoc = new TransferDoc();
                    transferDoc.setDocuments(mAuthTask.getGradeDocument());

                    GradesFragment nextFrag = GradesFragment.newInstance();
                    nextFrag.setDocument(transferDoc);

                    Bundle args = new Bundle();
                    args.putInt(JccappDefines.ARG_PAGE, JccappDefines.TAB_GRADES);
                    nextFrag.setArguments(args);

                    FragmentManager fragmentManager = getChildFragmentManager();
                    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                    fragmentTransaction.replace(R.id.fragment_container, nextFrag);
                    fragmentTransaction.addToBackStack(null);
                    fragmentTransaction.commit();
                }
            }
        }

        private Boolean checkEmptyField(EditText view) {

            String entry = view.getText().toString();

            if (TextUtils.isEmpty(entry)) {
                view.setError(getString(R.string.error_field_required));
                return false;
            }

            return true;
        }
    });

    mLoginFormView = login_fragment.findViewById(R.id.login_form);
    mProgressView = login_fragment.findViewById(R.id.login_progress);

}

fragment_login.xml

<LinearLayout 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:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".activities.HISPOSLoginActivity">

<!-- Login progress -->
<ProgressBar
    android:id="@+id/login_progress"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:visibility="gone" />

<ScrollView
    android:id="@+id/login_form"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/email_login_form"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <AutoCompleteTextView
                android:id="@+id/login"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/prompt_login"
                android:inputType="text"
                android:maxLines="1"
                android:singleLine="true" />

        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/prompt_password"
                android:imeActionId="@+id/login"
                android:imeActionLabel="@string/action_sign_in_short"
                android:imeOptions="actionUnspecified"
                android:inputType="textPassword"
                android:maxLines="1"
                android:singleLine="true" />

        </android.support.design.widget.TextInputLayout>

        <Button
            android:id="@+id/email_sign_in_button"
            style="?android:textAppearanceSmall"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:background="@color/colorMagenta"
            android:text="@string/action_sign_in"
            android:textColor="@android:color/white"
            android:textStyle="bold" />

    </LinearLayout>
</ScrollView>

带有fragment_page.xml ID

fragment_container

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</FrameLayout>

我希望你能帮助我,我不知道问题出在哪里,但对我来说非常有趣。

0 个答案:

没有答案