How to put the title of the Activity on the right of the toolbar
<p>I have written a code to shift the title of the activity to right.The following is the java code.I am using getSupportActionBar().</p>

<p>Here's the <a href="http://i.stack.imgur.com/x8OAs.png" rel="nofollow">Image of the toolbar I want</a></p>

<pre><code>   package com.example.hsports.practicesession;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

public class HomePage extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_home_page);

        String getUserEmail = getIntent().getExtras().getString("userEmail");
        String getUserPassword = getIntent().getExtras().getString("userPassword");


        TextView displayUserEmail= (TextView) findViewById(R.id.displayUserEmail);
        //this.setTitle("Welcome"+" "+getUserEmail);

       // getActionBar().setTitle("Welcome"+" "+getUserEmail);




        TextView displayUserPassword=(TextView)findViewById(R.id.displayUserPassword);


        displayUserEmail.setText(getUserEmail);
        displayUserPassword.setText(getUserPassword);







        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        TextView welcomeTextView = (TextView) toolbar.findViewById(R.id.welcomeText);
        welcomeTextView.setText("Welcome " + getUserEmail);


        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }

}
</code></pre>

<p>And this is the xml code which is for the Homepage.</p>

<pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout 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"

    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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.hsports.practicesession.HomePage"
    tools:showIn="@layout/activity_home_page"

    &gt;

    &lt;android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"

        &gt;

        &lt;android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay"

            /&gt;


        &lt;RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"&gt;
            &lt;TextView
                android:id="@+id/welcomeText"
                android:layout_marginRight="30dp"
                android:layout_alignParentRight="true"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" /&gt;
        &lt;/RelativeLayout&gt;

    &lt;/android.support.design.widget.AppBarLayout&gt;



    &lt;TextView
        android:id="@+id/displayUserEmail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" /&gt;

    &lt;TextView
        android:id="@+id/displayUserPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" /&gt;


&lt;/LinearLayout&gt;
</code></pre>

<p>I actually want the title of the page to come to right of the above action bar.
how to to do this.</p>

<p>The error I am getting is this:</p>

<p>07-14 00:03:03.763 3038-3038/com.example.hsports.practicesession E/AndroidRuntime: FATAL EXCEPTION: main
                                                                               Process: com.example.hsports.practicesession, PID: 3038
                                                                               java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hsports.practicesession/com.example.hsports.practicesession.HomePage}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
                                                                                   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.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
                                                                                   at com.example.hsports.practicesession.HomePage.onCreate(HomePage.java:46)
                                                                                   at android.app.Activity.performCreate(Activity.java:6237)
                                                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                                   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) </p>