-1

this is my activity from where I am sending Status

case R.id.buttonMade:
                {
                    Bundle bundle = new Bundle();
                    Status ="0";
                    bundle.putString("Status", Status);
                    FragmentAll fragInfo = new FragmentAll();
                    fragInfo.setArguments(bundle);
                    Log.e(bundle.toString(),bundle.toString());
                    startActivity(new Intent(FrontPageActivity.this, OrdersActivity.class));
                    break;
                }

This is my Fragment JAVA class

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View rootView = inflater.inflate(R.layout.fragment_order_all, container, false);
        sh_pref=getContext().getSharedPreferences("start", getContext().MODE_PRIVATE);
        uName = sh_pref.getString("username", null);

        final Bundle bundle = getArguments();
        Status1=bundle.getString("Status");
        if(Status1==null)
            Toast.makeText(getActivity(),"Null",Toast.LENGTH_LONG).show();

    >error is 

Java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference

I am able to pass data from activity but unable to get in fragment what the issue

Thank you

Pritish Joshi
  • 2,025
  • 3
  • 18
  • 33

2 Answers2

0

use this to fetch data :

Status1=getArguments().getString("Status");
Kapil Rajput
  • 11,429
  • 9
  • 50
  • 65
  • why u are passing Intent and startActivity ? – Kapil Rajput Dec 21 '15 at 09:04
  • code should be like this fragment.setArguments(bundle); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction() .replace(R.id.frame, fragment).commit(); – Kapil Rajput Dec 21 '15 at 09:05
0

In your case R.id.buttonMade listner

You set arguments to fragment but you did not attached bunble to intent startActivity(new Intent(FrontPageActivity.this, OrdersActivity.class));

If you have to pass it through intent then use this

i.putExtra("Status", Status);

for fragment - use this transaction -

                    Bundle bundle = new Bundle();
                    bundle.putString("Status", Status);
                    FragmentAll fragment = new FragmentAll ();
                    fragment.setArguments(bundle);
                    FragmentManager fragmentManager = getFragmentManager();
                    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                    fragmentTransaction.replace(R.id.container, fragment);
                    fragmentTransaction.addToBackStack(null);
                    fragmentTransaction.commit();
Ajinkya
  • 1,029
  • 7
  • 15