"Binary XML file android.widget.ProgressBar cannot be cast to android.view.ViewGroup" in progress bar

I have written a sign-In xml page and I am checking the eligibility of the user to login through Firebase database. Now after entering the username and password , I am clicking on the "Sign-In" button. It is taking few seconds to load the Home page after this. So I want to display a Progress Bar which revolves during that time and stops on opening the Home page.

My layout page for sing-In is:

<?xml version="1.0" encoding="utf-8"?>

<ProgressBar
    xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:id="@+id/loadingSignIn"
    android:indeterminate="true"
    android:visibility="invisible"
    >



<ScrollView

    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"

    android:layout_width="match_parent"
    >


    <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: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="com.example.hsports.bandpop.MainActivity"
        android:orientation="vertical"
        >


        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/title"
            android:text="WEDDING PLANNER"
            android:gravity="center"

            android:textSize="50dp"


            />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_gravity="center"

            android:paddingTop="100dp"
            >

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/Layout_username"
                android:hint="Username"
                >


                <AutoCompleteTextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/username"

                    android:gravity="center"

                    />


            </android.support.design.widget.TextInputLayout>
            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/Layout_password"
                android:hint="Password"
                >
                <AutoCompleteTextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/password"

                    android:gravity="center"
                    android:inputType="textPassword"
                    />

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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:paddingTop="50dp"

                >
                <Button
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="SIGN IN"
                    android:onClick="checkSignIn"
                    android:gravity="center"
                    android:id="@+id/SignInButton"
                    />

                <Button
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="REGISTER"
                    android:onClick="registerForm"
                    android:gravity="center"

                    />

            </LinearLayout>
        </LinearLayout>

    </LinearLayout>
</ScrollView>
</ProgressBar>

And the code as a fragment on clicking the "SignIn" button is:

package com.example.hsports.weddingplanner.Fragments;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import android.widget.ProgressBar;
import android.widget.TextView;

import com.example.hsports.weddingplanner.Activities.FrontPage;
import com.example.hsports.weddingplanner.Activities.WeddingPlanningUsers;
import com.example.hsports.weddingplanner.R;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

/**
 * Created by I324671 on 11/28/2016.
 */
public class SignIn extends Fragment {


    SharedPreferences sharedPreferences;
    String MyPreferences="loginUserInfo";
    ProgressBar afterSignIn;




    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) {

        final View view=inflater.inflate(R.layout.activity_login_page, container, false);

        afterSignIn=(ProgressBar)view.findViewById(R.id.loadingSignIn);


        Button checkSignIn=(Button)view.findViewById(R.id.SignInButton);

        checkSignIn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                afterSignIn.setVisibility(view.VISIBLE);
                final String username = ((TextView) (view.findViewById(R.id.username))).getText().toString();
                final String password = ((TextView) (view.findViewById(R.id.password))).getText().toString();

                FirebaseDatabase database = FirebaseDatabase.getInstance();
                DatabaseReference reference = database.getReference("Users");


                reference.addValueEventListener(new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {

                        if (dataSnapshot.hasChildren()) {
                            for (DataSnapshot child : dataSnapshot.getChildren()) {
                                String usernameFromDB=child.getKey().toString();
                                String passwordFromDB=child.getValue().toString();

                                if(username.equals(usernameFromDB)&& password.equals(passwordFromDB))
                                {

                                    sharedPreferences=getContext().getSharedPreferences(MyPreferences, Context.MODE_PRIVATE);
                                    SharedPreferences.Editor editor=sharedPreferences.edit();
                                    editor.putString("Username",username);
                                    editor.putString("Password", password);

                                    editor.commit();


                                    afterSignIn.setVisibility(view.GONE);
                                    Intent transferToHome=new Intent(getContext(), FrontPage.class);
                                    startActivity(transferToHome);
                                    break;

                                }
                               }
                        }

                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {

                        Log.d("The read failed", databaseError.getDetails());
                    }
                });

            }
        });

        return view;

    }
}

The error which I ma getting on executing this is : "Binary XML file android.widget.ProgressBar cannot be cast to android.view.ViewGroup". How can I resolve this.


ANSWERS:


The Problem is that you Have to close top tag inside XML:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">


<ProgressBar

    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:id="@+id/loadingSignIn"
    android:indeterminate="true"
    android:visibility="invisible"
    />

And: Use

   </LinearLayout>
</ScrollView>
   </LinearLayout>

You can have only one root of your layout file. Here you have two. namely ProgessBar and ScrollView. Try encapsulating them in FrameLayout and everything will be alright.

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


android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/loadingSignIn"
android:indeterminate="true"
android:visibility="invisible"
>



<ScrollView
    ...
  </ScrollView>
 </FrameLayout>

edit -->

for making progress bar center wise, change

<ProgressBar
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:id="@+id/loadingSignIn"
android:indeterminate="true"
android:visibility="invisible"
/>

and handle invisibility / visibility. :)



 MORE:


 ? cannot display progress bar at the time of loading another Activity in Android
 ? Is there a black progress bar to be visible on a white background?
 ? How to remove progress bar number at the bottom part of the progress bar?
 ? Vertical progress bar in android
 ? Custom indeterminate progress bar
 ? Progress bar inconvertable types; cannot cast error
 ? Remove progress bar from published document in MATLAB
 ? What is the basic idea behind programming a progress/status bar in MATLAB?
 ? Text progress bar in Matlab
 ? MATLAB update waitbar