title: Local Variable in Fragment class
body: <p>I have a fragment where I want to display values from a List, so I get it like this in Activity <strong>Recipe Detail</strong></p>
  
  <pre><code>        IngredientsFragment ingredientsFrag = new IngredientsFragment();
      ingredientsFrag.setPosition(position);
      ingredientsFrag.setRecipes(MainActivity.receipes);
      getSupportFragmentManager().beginTransaction()
              .replace(R.id.FRGingredients, ingredientsFrag)
              .commit();
  </code></pre>
  
  <p>The main thing up there to take note of is the <strong>SetRecipes()</strong> Method, I am passing in a <em>List</em>, it is a static List in the MainActivity class.</p>
  
  <p>In the Ingredients fragment I have this in <strong>Ingredient Fragment</strong>:</p>
  
  <pre><code>public class IngredientsFragment extends Fragment {
  int position;
   List&lt;Recipe&gt; mRecipes;
  String test;
  
  
  @Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.frag_recipe_ingredients, container, false);
      TextView ingredients = rootView.findViewById(R.id.ingredientsTxt);
  
      ingredients.setText(String.valueOf(mRecipes.get(0).getName()));
      return rootView;
  }
  
  public void setPosition(int position) {
      this.position = position;
  }
  
  public void setRecipes(List&lt;Recipe&gt; recipes) {
      test = String.valueOf(recipes.get(0).getName());
      mRecipes = recipes;
  }
  }
  </code></pre>
  
  <p>When I run this code this is what I get:</p>
  
  <pre><code>11-10 23:14:17.682 2812-2812/com.lemuel.lemubit.bakenow E/AndroidRuntime: FATAL EXCEPTION: main
          Process: com.lemuel.lemubit.bakenow, PID: 2812
          java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lemuel.lemubit.bakenow/com.lemuel.lemubit.bakenow.RecipeDetail}: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class fragment
                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2583)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2665)
          at android.app.ActivityThread.-wrap11(ActivityThread.java)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1499)
          at android.os.Handler.dispatchMessage(Handler.java:111)
          at android.os.Looper.loop(Looper.java:207)
          at android.app.ActivityThread.main(ActivityThread.java:5765)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
          Caused by: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class fragment
                                                                            at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
          at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
          at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
          at com.lemuel.lemubit.bakenow.RecipeDetail.onCreate(RecipeDetail.java:15)
          at android.app.Activity.performCreate(Activity.java:6360)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2530)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2665)
          at android.app.ActivityThread.-wrap11(ActivityThread.java)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1499)
          at android.os.Handler.dispatchMessage(Handler.java:111)
          at android.os.Looper.loop(Looper.java:207)
          at android.app.ActivityThread.main(ActivityThread.java:5765)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
          Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
                                                                            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
          at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
          at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
          at com.lemuel.lemubit.bakenow.RecipeDetail.onCreate(RecipeDetail.java:15)
          at android.app.Activity.performCreate(Activity.java:6360)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2530)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2665)
          at android.app.ActivityThread.-wrap11(ActivityThread.java)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1499)
          at android.os.Handler.dispatchMessage(Handler.java:111)
          at android.os.Looper.loop(Looper.java:207)
          at android.app.ActivityThread.main(ActivityThread.java:5765)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
          Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.List.get(int)' on a null object reference
          at com.lemuel.lemubit.bakenow.Fragments.IngredientsFragment.onCreateView(IngredientsFragment.java:34)
          at android.support.v4.app.Fragment.performCreateView(Fragment.java:2239)
          at android.support.v4.app.FragmentManagerImpl.ensureInflatedFragmentView(FragmentManager.java:1507)
          at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1303)
          at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1502)
          at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1737)
          at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3512)
          at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
          at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:330)
          at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39)
          at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:75)
          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:754)
          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
          at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
          at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
          at com.lemuel.lemubit.bakenow.RecipeDetail.onCreate(RecipeDetail.java:15)
          at android.app.Activity.performCreate(Activity.java:6360)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2530)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2665)
          at android.app.ActivityThread.-wrap11(ActivityThread.java)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1499)
          at android.os.Handler.dispatchMessage(Handler.java:111)
          at android.os.Looper.loop(Looper.java:207)
          at android.app.ActivityThread.main(ActivityThread.java:5765)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
  </code></pre>
  
  <p>So it does not recognize the variable <strong>mRecipes</strong>, but what puzzles me is that when I use the variable <strong>test</strong> it woks, which means that the list actually is passed down in the method, but anytime I try accessing it in onCreateView, it tell me that null error. Though I can access <strong>test</strong> if I change it to</p>
  
  <pre><code>ingredients.setText(test);
  </code></pre>
  
  <p>It works when I do it like that, which means OnCreateView is seeing variable <em>test</em> it also means that the List passed into the method initially was not null.</p>