Anonimo Anonimus Anonimo Anonimus - 29 days ago 21
Java Question

Passing data between Fragments with bundle object

I have two blank activites which holds two fragments.One activity is having adapter and it is acting as Tabactivity with adapter inside.

I want to pass data with intent and bundle inside.
When user enter email in Activity 1 and press button, email is going to appear on TextView inside Activity 2.

Here is exception I get :

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.presenter.utils.ui.AutoResizeTextView.setText(java.lang.CharSequence)' on a null object reference
at com.presenter.view.fragment.ForgotPasswordFragmentComplete.onCreate(ForgotPasswordFragmentComplete.java:50)
at android.support.v4.app.Fragment.performCreate(Fragment.java:2075)


I have created Intent and bundle:

@Bind(R.id.btn_forgot)
AppCompatButton btn_forgot;
@Bind(R.id.forgot_edittext)
AppCompatEditText editEmail;

public void onButtonClick() {
Intent intent = new Intent(".presenter.view.activity.ForgotPasswordCompleted");

intent.putExtra("email", editEmail.getText().toString());


ForgotPasswordFragment fragment = new ForgotPasswordFragment();
Bundle bundle = new Bundle();
bundle.putString("email",editEmail.getText().toString());
fragment.setArguments(bundle);


startActivity(intent);
}

Manifest:

<activity android:name=".presenter.view.activity.ForgotPasswordCompleted"
android:label="Forgot"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize">

<intent-filter>
<action android:name=".presenter.view.activity.ForgotPasswordCompleted"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>


I have binded textview with Dagger,added String getName and implemented intent and bundle in fragment 2:

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



Intent intent = getActivity().getIntent();
Bundle bd = intent.getExtras();
if ((bd != null)){
String getName = (String) bd.get("email");
resentTxt.setText(getName);
}

Answer

You have forgotten to written this line

InjectorClass.inject(this); 

in onCreate.