title: Why NullPointerException is giving on adding a tab?
body: <p>I am making an application in which I am having three tabs and respective fragment to that.But now I want to add one more tab but when I am adding it there is no issue but when i run my app it throws nullpointerexception.I dont why it is happening so.</p>
  
  <p>Please tell me where I m wrong.</p>
  
  <p>This my Activity in which all tab is there:</p>
  
  <pre><code>public class MainActivity extends  Activity { 
          RelativeLayout rl;
          PopupWindow popUp;
          LinearLayout layout;
          TextView tv;
          LayoutParams params;
          LinearLayout mainLayout;
          Button but;
          boolean click = true;
  
          ActionBar.Tab TabOrder , TabCart,TabHistory;
  
  
  
  
  
          @TargetApi(Build.VERSION_CODES.HONEYCOMB)
          @SuppressLint("NewApi")
          @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
  
              getOverflowMenu();
              rl = (RelativeLayout) findViewById(R.id.mainLayout);
              //fragMentTra = getFragmentManager().beginTransaction();
              ActionBar actionbar = getActionBar();
              actionbar.setTitle("Select To Order");
              actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
              //      bar.addTab(bar.newTab().setText("ORDER").setTabListener((TabListener) this));
              //      bar.addTab(bar.newTab().setText("CART").setTabListener(this));
              //      bar.addTab(bar.newTab().setText("HISTORY").setTabListener(this));
  
              //TabOrder = actionbar.newTab().setText("DEAL");
              TabOrder = actionbar.newTab().setText("ORDER");
              TabCart = actionbar.newTab().setText("CART");
              TabHistory = actionbar.newTab().setText("HISTORY");
  
              //Fragment FragmentDeal = new FragmentDeal();
              Fragment FragmentOrder = new FragmentOrder();
              Fragment FragmentCart = new FragmentCart();
              Fragment FragmentHistory = new FragmentHistory();
  
  
              //TabOrder.setTabListener(new MyTablistenerClass(FragmentDeal));
              TabOrder.setTabListener(new MyTablistenerClass(FragmentOrder));
              TabCart.setTabListener(new MyTablistenerClass(FragmentCart));
              TabHistory.setTabListener(new MyTablistenerClass(FragmentHistory));
  
  
              //actionbar.addTab(TabDeal);
              actionbar.addTab(TabOrder);
              actionbar.addTab(TabCart);
              actionbar.addTab(TabHistory);
  }
  
          private void getOverflowMenu() {
  
              try {
                  ViewConfiguration config = ViewConfiguration.get(this);
                  Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
                  if(menuKeyField != null) {
                      menuKeyField.setAccessible(true);
                      menuKeyField.setBoolean(config, false);
                  }
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
  </code></pre>
  
  <p><strong>FragmentOrder</strong>        </p>
  
  <pre><code>        @SuppressLint({ "ValidFragment", "NewApi" })
          public class FragmentOrder extends Fragment{
  
  
              @Override
              public View onCreateView(LayoutInflater inflater, ViewGroup container,
                      Bundle savedInstanceState) {
                  //View view = inflater.inflate(R.layout.g, null);
                  View view = inflater.inflate(R.layout.gridview,null);
                  final GridView listView = (GridView) view.findViewById(R.id.mainGrid);
                  listView.setAdapter(new OrderAdapter());
                  //listView.setSelection(setselected,true);
                  listView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
  
                  listView.setMultiChoiceModeListener(new MultiChoiceModeListener() {
  
  
                      @Override
                      public boolean onActionItemClicked(ActionMode mode,
                              MenuItem item) {
                          // TODO Auto-generated method stub
                          return true;
                      }
  
                      @Override
                      public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                          mode.setTitle("Select Items");
                          mode.setSubtitle("One item selected");
                          return true;
  
                      }
  
                      @Override
                      public void onDestroyActionMode(ActionMode mode) {
                          // TODO Auto-generated method stub
  
                      }
  
                      @Override
                      public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                          // TODO Auto-generated method stub
                          return false;
                      }
  
                      @Override
                      public void onItemCheckedStateChanged(ActionMode mode,
                              int position, long id, boolean checked) {
  
                          //listView.setLongClickable(false);
                          int selectCount = listView.getCheckedItemCount();
                          switch (selectCount) {
                          case 1:
                              mode.setSubtitle("One item selected");
                              break;
                          default:
                              mode.setSubtitle("" + selectCount +"items selected");
                              break;
  
                          }
                      }
                  });
  
  
                  return view;
              }
          }
  </code></pre>
  
  <p><strong>OrderAdapter</strong>   </p>
  
  <pre><code>        private class OrderAdapter extends BaseAdapter {
  
              @Override
              public int getCount() {
                  return mThumbIds.length;
              }
  
              @Override
              public Object getItem(int position) {
                  return null;
              }
  
              @Override
              public long getItemId(int position) {
                  // TODO Auto-generated method stub
                  return 0;
              }
  
              @Override
              public View getView(int position, View convertView, ViewGroup parent) {
  
                  //CheckableLayout l;
  
                  View myView = convertView;
  
                  LayoutInflater inflater = (LayoutInflater)MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);          
                  myView = inflater.inflate(R.layout.grid_items_ontap, null);
  
  
                  // Add The Image!!!           
                  ImageView iv = (ImageView)myView.findViewById(R.id.grid_item_image_OnTap);
                  iv.setImageResource(mThumbIds[position]);
  
  
                  // Add The Text!!!
                  TextView tv = (TextView)myView.findViewById(R.id.grid_item_text_onTap);
                  tv.setText(names[position] );
  
                  return myView;
              }
          }
  
          private Integer[] mThumbIds = {
                  R.drawable.car, R.drawable.car,
                  R.drawable.car, R.drawable.car,
                  R.drawable.car,R.drawable.car,R.drawable.car,R.drawable.car, R.drawable.car,
                  R.drawable.car, R.drawable.car,
                  R.drawable.car,R.drawable.car,R.drawable.car
          };
  
          private String[] names={"ab","cd","ef","gh","ij","kl","mn","","","","","","",""};
  </code></pre>
  
  <p><strong>FragmentHistory</strong>        </p>
  
  <pre><code>        @SuppressLint("ValidFragment")
          public class FragmentHistory extends Fragment{
  
              @Override
              public View onCreateView(LayoutInflater inflater, ViewGroup container,
                      Bundle savedInstanceState) {
  
                  View layout = inflater.inflate(R.layout.activity_fragmenthistory,   
                          (ViewGroup)  
                          findViewById(R.id.layout_root_history));   
  
  
                  ListView lv = (ListView) layout.findViewById(R.id.listViewHistory); 
                  lv.setAdapter(new HistoryListViewAdapter(MainActivity.this));  
  
                  lv.setOnItemClickListener(new OnItemClickListener() {
  
                      @Override
                      public void onItemClick(AdapterView&lt;?&gt; arg0, View view, int position,
                              long id) {
                          // TODO Auto-generated method stub
  
                          AlertDialog.Builder dlg = new AlertDialog.Builder(MainActivity.this);
  
  
                          dlg.setTitle("ORDERID");
  
                          dlg.setPositiveButton("REORDER",new DialogInterface.OnClickListener() {
  
                              @Override
                              public void onClick(DialogInterface dialog, int which) {
                                  // TODO Auto-generated method stub
                              }
  
                          })
  
                          .setNegativeButton("EDIT AND ORDER", new DialogInterface.OnClickListener() {
  
                              @Override
                              public void onClick(DialogInterface dialog, int which) {
                                  // TODO Auto-generated method stub
  
                              }
                          });
  
                          ListView listView = new ListView(MainActivity.this);
  
                          listView.setAdapter(new DialogListAdapter(MainActivity.this));
  
                          dlg.setView(listView);
                          //((Dialog) dlg).setCanceledOnTouchOutside(true);
                          // show it
                          dlg.show();
  
                      }
  
                  }); 
  
                  return layout;
              }
          }
  </code></pre>
  
  <p><strong>FragmentCart</strong>  </p>
  
  <pre><code>        @SuppressLint("ValidFragment")
          public class FragmentCart extends Fragment{
  
              @Override
              public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
                  View layout = inflater.inflate(R.layout.activity_fragmentcart,   
                          (ViewGroup)  
                          findViewById(R.id.layout_root_cart));   
  
  
                  ListView lv = (ListView) layout.findViewById(R.id.listViewCart); 
                  lv.setAdapter(new CartListViewAdapter(MainActivity.this));
  
                  //lv.invalidateViews();
  
  
                  return layout;
              }
  
          }
  </code></pre>
  
  <p><strong>FragmentDeal</strong>        </p>
  
  <pre><code>        @SuppressLint("ValidFragment")
          public class FragmentDeal extends Fragment{
  
  
              @Override
              public View onCreateView(LayoutInflater inflater, ViewGroup container,
                      Bundle savedInstanceState) {
  
                  View layout = inflater.inflate(R.layout.fragmentdeal,   
                          (ViewGroup)  
                          findViewById(R.id.layoutdeal));   
  
  
                  //View view = inflater.inflate(R.layout.griddeal,null);
                  final GridView listView = (GridView) layout.findViewById(R.id.GridDeal);
                  listView.setAdapter(new DealAdapter());
  
                  listView.setOnItemClickListener(new OnItemClickListener() {
  
                      @Override
                      public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1,
                              int arg2, long arg3) {
                          // TODO Auto-generated method stub
  
                      }
                  });
  
                  return layout;
                  // TODO Auto-generated method stub
  
  
              }
          }
  
          private class DealAdapter extends BaseAdapter {
  
              @Override
              public int getCount() {
                  return mThumbIds1.length;
              }
  
              @Override
              public Object getItem(int position) {
                  return null;
              }
  
              @Override
              public long getItemId(int position) {
                  // TODO Auto-generated method stub
                  return 0;
              }
  
              @Override
              public View getView(int position, View convertView, ViewGroup parent) {
  
                  //CheckableLayout l;
  
                  View myView = convertView;
  
                  LayoutInflater inflater = (LayoutInflater)MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);          
                  myView = inflater.inflate(R.layout.griddealitems, null);
  
  
                  // Add The Image!!!           
                  ImageView iv = (ImageView)myView.findViewById(R.id.grid_deal_image);
                  iv.setImageResource(mThumbIds1[position]);
  
  
                  // Add The Text!!!
                  TextView tv = (TextView)myView.findViewById(R.id.grid_deal_text);
                  tv.setText(names1[position] );
  
  
  
  
                  return myView;
              }
              private Integer[] mThumbIds1 = {
                      R.drawable.car, R.drawable.car,
                      R.drawable.car, R.drawable.car
  
              };
  
              private String[] names1={"ab","cd","ef","gh"};
          }
          @Override
          public boolean onCreateOptionsMenu(Menu menu) {
              MenuInflater inflater = getMenuInflater();
              inflater.inflate(R.menu.main, menu);
              return true;
  
          }
  
  
  
          public boolean onOptionsItemSelected(MenuItem item){
  
              switch(item.getItemId()){
              case R.id.action_settings:
                  Intent intentForSettings = new Intent(MainActivity.this, SettingsMenu.class);
                  startActivity(intentForSettings);
                  return true;
  
              case R.id.action_info:
                  Intent intentForInformation = new Intent(MainActivity.this,InformationMenu.class);
                  startActivity(intentForInformation);
                  return true;
  
              case R.id.action_ContactUs:
                  Intent dial = new Intent();
                  String no =  "9579839314";
                  dial.setAction("android.intent.action.DIAL");
                  dial.setData(Uri.parse("tel:"+ no));
                  startActivity(dial); 
                  return true;
  
              }
              return false;
  
          }
  
          public class MyTablistenerClass implements android.app.ActionBar.TabListener {
  
              Fragment fragment1;
  
              @SuppressLint("NewApi")
              public MyTablistenerClass(Fragment fragment){
                  this.fragment1 = fragment;
              }
  
  
              @Override
              public void onTabReselected(Tab tab, FragmentTransaction ft) {
                  // TODO Auto-generated method stub
  
              }
              @Override
              public void onTabSelected(Tab tab, FragmentTransaction ft) {
                  // TODO Auto-generated method stub
  
  
                  FragmentTransaction fragMentTra;
                  if (tab.getText().equals("DEAL")) {
                      try {
                          rl.removeAllViews();
                      } catch (Exception e) {
                      }
                  FragmentDeal Fram1 = new FragmentDeal();
                      //fragMentTra.addToBackStack(null);
                      fragMentTra = getFragmentManager().beginTransaction();
                      fragMentTra.add(rl.getId(), Fram1);
                      fragMentTra.commit();
                  }
                  else if (tab.getText().equals("ORDER")) {
                      try {
                          rl.removeAllViews();
                      } catch (Exception e) {
                      }
                      FragmentOrder Fram2 = new FragmentOrder();
                      //fragMentTra.addToBackStack(null);
                      fragMentTra = getFragmentManager().beginTransaction();
                      fragMentTra.add(rl.getId(), Fram2);
                      fragMentTra.commit();
                  }
  
                  else if(tab.getText().equals("CART")){
                      try {
                          rl.removeAllViews();
                      } catch (Exception e) {
                      }
                      FragmentCart fram3 = new FragmentCart();
                      //fragMentTra.addToBackStack(null);
                      fragMentTra = getFragmentManager().beginTransaction();
                      fragMentTra.add(rl.getId(), fram3);
                      fragMentTra.commit();
                  }
  
  
  
                  else if(tab.getText().equals("HISTORY")){
                      try {
                          rl.removeAllViews();
                      } catch (Exception e) {
                      }
                      FragmentHistory fram4 = new FragmentHistory();
                      //fragMentTra.addToBackStack(null);
                      fragMentTra = getFragmentManager().beginTransaction();
                      fragMentTra.add(rl.getId(), fram4);
                      fragMentTra.commit();
                  }
  
              }
              @Override
              public void onTabUnselected(Tab tab, FragmentTransaction ft) {
                  // TODO Auto-generated method stub
  
              }
  
          }
      }
  </code></pre>
  
  <p>On adding tabdeal I am facing problem.FragmentDeal is its respective Fragment.If anyone can see where I am wrong tell me.
  Thanks.</p>