I want to send a string from one activity to a fragment. Here is what I am doing in my activity class. I am getting the string from a json object and sending it to the fragment class. But I am getting null as response. How to solve this?

```
 public final static String EXTRA_MESSAGE = "LoginActivity.java";

 JSONObject mainObject2 = new JSONObject(responseStr2);
 String Name = mainObject2.getString("Name");
 Intent i = new Intent(getApplicationContext(),HomeFragment.class);
 Bundle b = new Bundle();
 b.putString("Name", Name);
 i.putExtras(b);
 startActivity(i);

```

Below is what I am doing in my fragment class. I am trying to receive the string and show it on a textview.

```
 public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
 View rootView = inflater.inflate(R.layout.fragment_home, container, false);
 String Name = getActivity().getIntent().getStringExtra(LoginActivity.EXTRA_MESSAGE);
 name = (TextView) rootView.findViewById(R.id.name);
 name.setText(Name);

```

UPDATE 1:

My LogCat is showing the following.

```
03-23 13:26:13.756: E/AndroidRuntime(2540):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
03-23 13:26:13.756: E/AndroidRuntime(2540):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
03-23 13:26:13.756: E/AndroidRuntime(2540):     at android.app.ActivityThread.access$800(ActivityThread.java:144)
03-23 13:26:13.756: E/AndroidRuntime(2540):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
03-23 13:26:13.756: E/AndroidRuntime(2540):     at android.os.Handler.dispatchMessage(Handler.java:102)
03-23 13:26:13.756: E/AndroidRuntime(2540):     at android.os.Looper.loop(Looper.java:135)
03-23 13:26:13.756: E/AndroidRuntime(2540):     at android.app.ActivityThread.main(ActivityThread.java:5221)
03-23 13:26:13.756: E/AndroidRuntime(2540):     at java.lang.reflect.Method.invoke(Native Method)
03-23 13:26:13.756: E/AndroidRuntime(2540):     at java.lang.reflect.Method.invoke(Method.java:372)
03-23 13:26:13.756: E/AndroidRuntime(2540):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
03-23 13:26:13.756: E/AndroidRuntime(2540):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
03-23 13:26:13.756: E/AndroidRuntime(2540): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
03-23 13:26:13.756: E/AndroidRuntime(2540):     at com.webgentechnology.kidskula.HomeFragment.onCreateView(HomeFragment.java:81)
03-23 13:26:13.756: E/AndroidRuntime(2540):     at android.app.Fragment.performCreateView(Fragment.java:2053)
03-23 13:26:13.756: E/AndroidRuntime(2540):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
03-23 13:26:13.756: E/AndroidRuntime(2540):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
03-23 13:26:13.756: E/AndroidRuntime(2540):     at android.app.BackStackRecord.run(BackStackRecord.java:833)
03-23 13:26:13.756: E/AndroidRuntime(2540):     at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
03-23 13:26:13.756: E/AndroidRuntime(2540):     at android.app.Activity.performStart(Activity.java:5948)
03-23 13:26:13.756: E/AndroidRuntime(2540):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)
03-23 13:26:13.756: E/AndroidRuntime(2540):     ... 10 more
03-23 13:26:19.086: I/Process(2540): Sending signal. PID: 2540 SIG: 9
03-23 13:26:25.097: I/art(2750): Background partial concurrent mark sweep GC freed 30(3KB) AllocSpace objects, 0(0B) LOS objects, 24% free, 3MB/4MB, paused 11.746ms total 39.506ms
03-23 13:26:26.204: I/art(2750): Background partial concurrent mark sweep GC freed 77(3KB) AllocSpace objects, 0(0B) LOS objects, 20% free, 7MB/9MB, paused 7.144ms total 58.002ms
03-23 13:26:26.726: D/gralloc_goldfish(2750): Emulator without GPU emulation detected.

```

UPDATE 2:

Below is my XML file. There are two tabs in this layout. The following code is one of the tabs.

```
 <RelativeLayout
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:id="@+id/notificationtab"
               android:orientation="vertical"
               android:paddingTop="0dp"  >    

            <Button 
                 android:id="@+id/btn_Delete"
                 android:layout_height="44dp"
                 android:layout_width="78dp"
                 android:text="@string/Archieve"
                 android:textColor="#ffffff"
                 android:layout_marginTop="30dp"
                 android:background="@drawable/custombutton5"
                 android:textSize="18sp"
                 android:layout_marginRight="15dp"
                 android:layout_alignParentRight="true"/>

              <RelativeLayout 
                    android:id="@+id/relative_layout2"
                    android:layout_height="wrap_content"
                    android:layout_width="fill_parent"
                    android:layout_marginTop="90dp">

                 <ListView 
                      android:id="@+id/listView"
                      android:layout_height="wrap_content"
                      android:layout_width="match_parent"
                      android:choiceMode="multipleChoice"> 
                 </ListView>

             </RelativeLayout>

         <CheckBox
              android:id="@+id/chkbox"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignBottom="@+id/btn_Retrieve_All_Notification"
              android:layout_alignParentLeft="true"
              android:layout_marginLeft="15dp"
              android:text="@string/CHECK"
              android:textSize="18sp"
              android:textStyle="bold"
              android:textColor="#f33347" />

         <Button
             android:id="@+id/btn_Retrieve_All_Notification"
             android:layout_width="215dp"
             android:layout_height="45dp"
             android:layout_alignBaseline="@+id/btn_Delete"
             android:layout_alignBottom="@+id/btn_Delete"
             android:layout_marginRight="25dp"
             android:layout_toLeftOf="@+id/btn_Delete"
             android:background="@drawable/custombutton5"
             android:text="@string/Retrive"
             android:textColor="#ffffff"
             android:textSize="18sp" />

           </RelativeLayout>   

```

Also the referenced line of java is below:

```
//This is line 81
lst_vw.setAdapter(new Adapterclass(getActivity().getBaseContext()));

```

---

Solved:

I have solved the problem by using Shared Preferences.