Nullpointerexception On Android.os.bundle
I have some problem with my code, when I need to transfer some data from one Activity to another one. First Activity (ViewCashflow) and I want transfer some data from ViewCashflow
Solution 1:
This is happen because when you start your second activity NewTransaction
directly you don't put extras
in the intent
, so when you call getIntent().getExtras();
it returns a null
object and this is why getIntent().getExtras().getBoolean("update");
throw the NPE.
As solution: try to check if getIntent().getExtras() != null
before getting the data, this will fix your problem.
Bundle bundle= getIntent().getExtras();
if (bundle!= null) {// to avoid the NullPointerException
isUpdate=bundle.getBoolean("update");
if(isUpdate)
{
id=bundle.getString("TransId");
transname=bundle.getString("TransName");
transamount=bundle.getString("TransAmount");
transtype=bundle.getString("TransType");
transdate=bundle.getString("CategDate");
transcategid=bundle.getString("CategCategId");
txtCashflow.setText(transname);
txtType.setText(transtype);
txtAmount.setText(transamount);
}
}
Solution 2:
Try this in your ViewCashFlow class:
Intent i = newIntent(Context.getApplicationContext(), NewTransaction.class);
Solution 3:
if it in fragment you can use :
if (getArguments() != null) {
loginBody = getArguments().getParcelable(getActivity().getResources().getString(R.string.logInBodyParcelData));
}
/* } catch (Exception e) {
e.printStackTrace();
}*/if (loginBody != null) {
setProfile();
}
Post a Comment for "Nullpointerexception On Android.os.bundle"