title: Android ArrayAdapter getActivity() returns null
body: <p>I have problem with getting the Activity from my Fragment. I have read several threads here and I am convinced that it shoud work, but I am still getting null from getActivity() method in my onAttach() method in my fragment.</p>
  
  <p>My code:</p>
  
  <pre><code>public static class TabsAdapter extends FragmentPagerAdapter implements ActionBar.TabListener, ViewPager.OnPageChangeListener {
      private final FragmentActivity mContext;
      private final ActionBar mActionBar;
      private final ViewPager mViewPager;
      private final ArrayList&lt;TabInfo&gt; mTabs = new ArrayList&lt;TabInfo&gt;();
      private Fragment mFragment;
  
  
      static final class TabInfo {
          private final Class&lt;?&gt; clss;
          private final Bundle args;
  
          TabInfo(Class&lt;?&gt; _class, Bundle _args) {
              clss = _class;
              args = _args;
          }
      }
  
      public TabsAdapter(SherlockFragmentActivity activity, ViewPager pager) {
          super(activity.getSupportFragmentManager());
          mContext = activity;
          mActionBar = activity.getSupportActionBar();
          mViewPager = pager;
          mViewPager.setAdapter(this);
          mViewPager.setOnPageChangeListener(this);
      }
  
      public void addTab(ActionBar.Tab tab, Class&lt;?&gt; clss, Bundle args) {
          TabInfo info = new TabInfo(clss, args);
          tab.setTag(info);
          tab.setTabListener(this);
          mTabs.add(info);
          mActionBar.addTab(tab);
          notifyDataSetChanged();
      }
  
      @Override
      public int getCount() {
          return mTabs.size();
      }
  
      @Override
      public Fragment getItem(int position) {
          TabInfo info = mTabs.get(position);
          FragmentTransaction ft=mContext.getSupportFragmentManager().beginTransaction();
          Fragment fragment=Fragment.instantiate(mContext, info.clss.getName(), info.args);
          if(mFragment==null || !mFragment.equals(fragment)){
              mFragment=fragment;
              ft.add(mViewPager.getId(), mFragment);  
              ft.commit();
          }else{
              ft.detach(mFragment);
              mFragment=fragment;
              ft.attach(mFragment);
              ft.commit();
          }           
          return mFragment;
      }
  
      @Override
      public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
      }
  
      @Override
      public void onPageSelected(int position) {
          mActionBar.setSelectedNavigationItem(position);
      }
  
      @Override
      public void onPageScrollStateChanged(int state) {
      }
  
      @Override
      public void onTabSelected(Tab tab, FragmentTransaction ft) {
          Object tag = tab.getTag();
          for (int i = 0; i &lt; mTabs.size(); i++) {
              if (mTabs.get(i) == tag) {
                  mViewPager.setCurrentItem(i);                   
              }
          }
  
  
      }
  
      @Override
      public void onTabUnselected(Tab tab, FragmentTransaction ft) {
  
  
      }
  
      @Override
      public void onTabReselected(Tab tab, FragmentTransaction ft) {
      }
  }
  </code></pre>
  
  <p>and I call.</p>
  
  <pre><code>setListAdapter(new CompaniesListAdapter(getActivity(), records));
  </code></pre>
  
  <p>From my onAttach() method in my Fragment as it is described in several threads.</p>
  
  <p>I have tried almost everything, but I can't make it return the Activity. Thank you very much in advance for your answers.</p>
  
  <p>log:</p>
  
  <pre><code>07-27 11:30:57.648: E/AndroidRuntime(18378): FATAL EXCEPTION: main
  07-27 11:30:57.648: E/AndroidRuntime(18378): java.lang.NullPointerException
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at  com.citysmartgo.cheaptaxi.tabs.support.CompaniesListAdapter.getView(CompaniesListAdapter.java:59)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.widget.AbsListView.obtainView(AbsListView.java:2033)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.widget.ListView.makeAndAddView(ListView.java:1772)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.widget.ListView.fillDown(ListView.java:672)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.widget.ListView.fillFromTop(ListView.java:732)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.widget.ListView.layoutChildren(ListView.java:1625)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.widget.AbsListView.onLayout(AbsListView.java:1863)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.view.View.layout(View.java:11278)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.view.View.layout(View.java:11278)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1388)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.view.View.layout(View.java:11278)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.view.View.layout(View.java:11278)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.view.View.layout(View.java:11278)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.view.View.layout(View.java:11278)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1489)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.os.Handler.dispatchMessage(Handler.java:99)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.os.Looper.loop(Looper.java:137)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at android.app.ActivityThread.main(ActivityThread.java:4424)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at java.lang.reflect.Method.invokeNative(Native Method)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at java.lang.reflect.Method.invoke(Method.java:511)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  07-27 11:30:57.648: E/AndroidRuntime(18378):    at dalvik.system.NativeStart.main(Native Method)
  07-27 11:30:58.874: I/Process(18378): Sending signal. PID: 18378 SIG: 9
  </code></pre>
  
  <p>my getView method</p>
  
  <pre><code>@Override
  public View getView(int position, View convertView, ViewGroup parrent){
      View rowView = convertView;
      TaxiCompanyQuoteView cqView = null;
  
      if(rowView == null) {
          LayoutInflater inflater = activity.getLayoutInflater();
          rowView = inflater.inflate(R.layout.companies_row_layout, null);
  
          cqView=new TaxiCompanyQuoteView();
          cqView.company=(TextView) rowView.findViewById(R.id.companies_name);
          cqView.company=(TextView) rowView.findViewById(R.id.companies_phone);
          cqView.company=(TextView) rowView.findViewById(R.id.companies_price_per_unit);
          cqView.company=(TextView) rowView.findViewById(R.id.companies_entering_price);
          cqView.company=(TextView) rowView.findViewById(R.id.companies_waiting_price);
  
          rowView.setTag(cqView);
      }else{
          cqView = (TaxiCompanyQuoteView) rowView.getTag();
      }
  
      TaxiCompany currentTaxiCompany = taxiCompanies.get(position);
      cqView.company.setText(currentTaxiCompany.getName());
      cqView.phone.setText(currentTaxiCompany.getNumber());
      cqView.pricePerUnit.setText(currentTaxiCompany.getPricePerUnit());
      cqView.waitingPrice.setText(currentTaxiCompany.getEnteringPrice());
      cqView.enteringPrice.setText(currentTaxiCompany.getWaitingPrice());
  
      return rowView;
  }
  </code></pre>