-1

I need help or recomendation for solve this problem

CODE FROM Fragment A

   @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
     //Origin to send variable

    String valor3;

    Intent intent = new Intent(getActivity(), MainFragment.class);
    Bundle bundle = new Bundle();
    //bundle.putString("row_s",valor3);
    intent.putExtra("row_S",valor3);
    startActivity(intent);
}

CODE FROM Fragment B

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

    Intent intent = getActivity().getIntent();
    recibeBundle = getActivity().getIntent().getStringExtra("row_s");

   ROW_SIZE = (Integer.parseInt(recibeBundle));

    initData();
}

With ROW_SIZE =.. Launch this ERROR

**//Identified Problem - NPE Attempt to invoke virtual method 'int android.os.Bundle.getInt(java.lang.String)' on a null object reference at

com.project.ignacio_rvf_bbf.bbf_reporter.MainFragment.onCreate(MainFragment.java:99)**

Thanks a lot friends!

Ignacio_aa
  • 318
  • 2
  • 8
  • Please paste the line 99 of your MainFragment.java ... – Thomas Mary Jan 24 '18 at 21:37
  • I find it best to use a `public static final String` to maintain consistency for names of extras! It looks like you have used to different strings: "row_s" and "row_S" (capital "S"). Besides that it also looks like you have not assigned a value to your variable "valor3". – Barns Jan 24 '18 at 21:59

2 Answers2

1

Your parameter is null because the name of the key must be the same

for example, in your first activity you have:

intent.putExtra("row_S",valor3);

the name of the key is: "rwo_S" with the capital letter S

and in the second activity you have:

recibeBundle = getActivity().getIntent().getStringExtra("row_s");

the name of the key is: "rwo_s" with minuscule s.

The name must be the same.

I hope it helps you.

0

Error : getInt is called in a null Bundle object

Thomas Mary
  • 1,535
  • 1
  • 13
  • 24