Passing a string value(date) from an activity to another fragment's textview
<p>I'm having null values from passing a string value which contains time&amp;date from an activity to another fragment that carries the textview. Is there a method to carry these values into another one of my fragment's java class(Notifications.java)?</p>

<pre><code>            date = (TextView) view.findViewById(R.id.textDate);
            date.setText(DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime()));
</code></pre>

<p>I got this error:</p>

<pre><code>rogue.queue E/AndroidRuntime: FATAL EXCEPTION: main
                                                                      Process: rogue.queue, PID: 20762
                                                                      java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
                                                                          at rogue.queue.MainActivity$1.onClick(MainActivity.java:76)
</code></pre>

<p>Using the fab button to pass the value to another fragment:</p>

<pre><code>FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Snackbar.make(view, "Add a new queue", Snackbar.LENGTH_LONG)
                .setAction("Action", null).show();
            fragmentManager.beginTransaction().replace(R.id.content_main, new Notifications()).commit();
            date = (TextView) view.findViewById(R.id.textDate);
        date.setText(DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime()));
        navigationView.setCheckedItem(R.id.nav_notifications);
    }
});
</code></pre>

<p>Here's my Notifications java class for the fragment</p>

<pre><code>public class Notifications extends Fragment {
TextView servingqueue;
TextView date;
String dateGET;

DatabaseReference mRootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference mServingQueue = mRootRef.child("ServingQueue");


public Notifications() {
    // Required empty public constructor
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle pb=getArguments();
    dateGET=pb.getString("date");


    mServingQueue.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            Double number = dataSnapshot.getValue(Double.class);
            servingqueue.setText(String.valueOf(number));

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}

@Override
public void onAttach(Context context) {
    super.onAttach(context);

}

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

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_notifications, container, false);
    // Inflate the layout for this fragmentid.queueServing);
    servingqueue = (TextView) rootView.findViewById(R.id.queueServing);
    return rootView;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    date = (TextView) view.findViewById(R.id.textDate);
//        date.setText(DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime()));
    date.setText(dateGET);

    }
}
</code></pre>

<p>Here is my mainactivity</p>

<pre><code>public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener, Home.OnFragmentInteractionListener {
    //Read Firebase Database

    private FirebaseAuth firebaseAuth;
    private TextView textViewUserEmail;
    private MenuItem nav_logout;
    TextView servingqueue;
TextView date;


FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

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

    //Launches Home() fragment
    fragmentManager.beginTransaction().replace(R.id.content_main, new Home()).commit();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    final NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    navigationView.setCheckedItem(R.id.nav_home);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Add a new queue", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
//                Queue.getQueue();
                fragmentManager.beginTransaction().replace(R.id.content_main, new Notifications()).commit();
//                date = (TextView) view.findViewById(R.id.textDate);
//         

   date.setText(DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime()));

            Fragment fragment2=new Notifications();
            Bundle arg= new Bundle();
            arg.putString("date","DATE");
            fragment2.setArguments(arg);
            FragmentManager fragmentManager = getSupportFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.content_main, fragment2);

            fragmentTransaction.commit();

//                fragmentManager.beginTransaction().replace(R.id.content_main,fragment2).commit();

            navigationView.setCheckedItem(R.id.nav_notifications);
        }
    });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();



    //User Profile Interface
    firebaseAuth = FirebaseAuth.getInstance();
    if (firebaseAuth.getCurrentUser() == null) {
        startActivity(new Intent(this, Login.class));
    }
    FirebaseUser user = firebaseAuth.getCurrentUser();

    View HeaderView = navigationView.getHeaderView(0);
    textViewUserEmail = (TextView) HeaderView.findViewById(R.id.textViewUserEmail);
    textViewUserEmail.setText("Welcome "+user.getEmail());
//        nav_logout = (MenuItem) findViewById(R.id.nav_logout);
//        nav_logout.setOnClickListener(this);

}

@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    }
     else {
        super.onBackPressed();
    }
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_home) {
        fragmentManager.beginTransaction().replace(R.id.content_main, new Home()).commit();
    } else if (id == R.id.nav_notifications) {
        fragmentManager.beginTransaction().replace(R.id.content_main, new Notifications()).commit();
    } else if (id == R.id.nav_settings) {
        fragmentManager.beginTransaction().replace(R.id.content_main, new Settings()).commit();
    } else if (id == R.id.nav_logout) {
        firebaseAuth.signOut();
        finish();
        startActivity(new Intent (this, Login.class));
    }
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

@Override
public void onFragmentInteraction(Uri uri) {

}

public void onClick(View v) {
    Intent intent = new Intent (this, Scanner.class);
    startActivity(intent);
}

}
</code></pre>

<p>Here is the xml that i am editing:</p>

<p>Fragment:</p>

<pre><code>&lt;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"
tools:context="rogue.queue.Notifications"
android:id="@+id/notification_relative_layout"&gt;

&lt;!-- TODO: Update blank fragment layout --&gt;

&lt;TextView
    android:text="Your Number:"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="72dp"
    android:id="@+id/textView3"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" /&gt;

&lt;TextView
    android:text="0000"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView3"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="40dp"
    android:id="@+id/myqueue"
    android:textSize="40sp" /&gt;

&lt;TextView
    android:text="Current Number:"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textView9"
    android:layout_marginTop="62dp"
    android:layout_below="@+id/myqueue"
    android:layout_toStartOf="@+id/myqueue" /&gt;

&lt;TextView
    android:text="PLEASE BE SEATED"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="78dp"
    android:id="@+id/textView15"
    android:layout_below="@+id/queueServing"
    android:layout_centerHorizontal="true" /&gt;

&lt;TextView
    android:text="-"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/queueServing"
    android:layout_alignBaseline="@+id/textView9"
    android:layout_toEndOf="@+id/myqueue" /&gt;

&lt;TextView
    android:text="YOU WILL BE SERVED SHORTLY"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="19dp"
    android:id="@+id/textView14"
    android:layout_below="@+id/textView15"
    android:layout_centerHorizontal="true" /&gt;

&lt;TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="Welcome to Sunway Education Group"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true" /&gt;

&lt;TextView
    android:text="TextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textDate"
    tools:text="00 - JAN - 0000"
    android:layout_below="@+id/textView14"
    android:layout_alignEnd="@+id/textView9" /&gt;

&lt;Button
    android:text="CANCEL QUEUE"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="21dp"
    android:id="@+id/buttonQueueCancel"
    android:background="@android:color/holo_red_light"
    /&gt;
</code></pre>

<p></p>

<p>Here is the app_main_bar of where the fab is located at linking to the mainactivity.java</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
</code></pre>

<p></p>

<pre><code>&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;/android.support.design.widget.AppBarLayout&gt;

&lt;include layout="@layout/content_main" /&gt;

&lt;android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    app:srcCompat="@drawable/ic_add_white_24px" /&gt;
</code></pre>

<p></p>