title: How to apply custom font to multiple TextViews within a fragment?
body: <p>I am trying to change the default font for multiple TextViews in android fragment by a custom font. The code to accomplish this is in onCreateView of thefragment  as shown below:</p>
  
  <pre><code>@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      View v = inflater.inflate(R.layout.fragment_interest, container, false);
      TextView txt1 = (TextView)v.findViewById(R.id.textView1);
      TextView txt2 = (TextView)v.findViewById(R.id.textView2);
      Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/HoneyScript-SemiBold.ttf");
  
      txt1.setTypeface(font);
      txt2.setTypeface(font);
  
      return v;
  </code></pre>
  
  <p>}</p>
  
  <p>The code works if I change the font for only a single TextView  but attempting to change font for multiple TextViews as in the code above, I am getting NullPointerException error:</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setTypeface(android.graphics.Typeface)' on a null object reference
                                                                                       at layout.InterestFragment.onCreateView(InterestFragment.java:81)
                                                                                       at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
                                                                                       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
                                                                                       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
                                                                                       at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
                                                                                       at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
                                                                                       at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:330)
                                                                                       at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:547)
                                                                                       at com.android.niraj.financialcalculator.MainActivity.onStart(MainActivity.java:221)
                                                                                       at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1237)
                                                                                       at android.app.Activity.performStart(Activity.java:6253)
                                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
                                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                                       at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                       at android.os.Looper.loop(Looper.java:148) 
                                                                                       at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
  </code></pre>
  
  <p>I am newbie to java and android programming. Please help me find a solution in changing all the TextViews in the fragment with custom font. Thanks in advance !!</p>