title: Android Calling Activity from Fragment crashes app
body: <p>I am trying to call my activity from a fragment and it crashes on start.</p>
  
  <p>Here is my fragment code that calls the activity (Extends SherlockFragment):</p>
  
  <pre><code>public class SalesOrder extends SherlockFragment{
  
      ListView myInfoList;
      String[] items = {"Item 1", "Item 2"};
      ArrayAdapter&lt;CharSequence&gt; adapter;
  
      ArrayList&lt;MessageDetails&gt; details;
      AdapterView.AdapterContextMenuInfo info;
  
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
  
          View view = inflater.inflate(R.layout.sales_order, container, false);
  
          return view;
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onActivityCreated(savedInstanceState);
          refreshListView();
      }
  
      private void refreshListView()
      {
          myInfoList = (ListView)getActivity().findViewById(R.id.MessageList);
          adapter = new ArrayAdapter&lt;CharSequence&gt;(getActivity().getApplicationContext(), android.R.layout.simple_list_item_1, items);
          myInfoList.setAdapter(adapter);
  
          details = new ArrayList&lt;MessageDetails&gt;();
          MessageDetails Detail;
  
          //CHANGE THIS PART TO RETRIEVE DATABASE ITEM DYNAMICALLY
          List&lt;String&gt; itemName = new ArrayList&lt;String&gt;();
          itemName.add("Shirt Design 1");
          itemName.add("Shirt Design 2");
          itemName.add("Shirt Design 3");
  
          List&lt;Float&gt; itemPrice = new ArrayList&lt;Float&gt;();
          itemPrice.add(14f);
          itemPrice.add(15f);
          itemPrice.add(16f);
  
          List&lt;String&gt; description = new ArrayList&lt;String&gt;();
          description.add("This is a fine shirt 1");
          description.add("This is a fine shirt 2");
          description.add("This is a fine shirt 3");
  
          Detail = new MessageDetails();
  
          for (int i =0; i &lt; itemName.size(); i++)
          {
              Detail = new MessageDetails();
              Detail.setSub(itemName.get(i));
              Detail.setSubValue(itemPrice.get(i));
              Detail.setDescription(description.get(i));
              details.add(Detail);
          }   
  
          myInfoList.setAdapter(new CustomAdapter(details , getActivity().getApplicationContext()));
  
          myInfoList.setOnItemClickListener(new OnItemClickListener() {
                 public void onItemClick(AdapterView&lt;?&gt; a, View v, int position, long id) {
                     //System.out.println("Name: "+details.get(position).getSub();
                     //String s = details.get(position).getDescription();
  
                     Intent i = new Intent(getActivity(), purchase.class);
                     getActivity().startActivity(i);
                 }
         });  
      }
  
      public class CustomAdapter extends BaseAdapter {
  
          private ArrayList&lt;MessageDetails&gt; _data;
          Context _c;
  
          CustomAdapter (ArrayList&lt;MessageDetails&gt; data, Context c){
              _data = data;
              _c = c;
          }
  
          public int getCount() {
              // TODO Auto-generated method stub
              return _data.size();
          }
  
          public Object getItem(int position) {
              // TODO Auto-generated method stub
              return _data.get(position);
          }
  
          public long getItemId(int position) {
              // TODO Auto-generated method stub
              return position;
          }
  
          public View getView(final int position, View convertView, ViewGroup parent) {
              // TODO Auto-generated method stub
               View v = convertView;
               if (v == null) 
               {
                  LayoutInflater vi = (LayoutInflater)_c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                  v = vi.inflate(R.layout.mysaleslistview, null);
               }
                 TextView subView = (TextView)v.findViewById(R.id.itemName);
                 TextView subValueView = (TextView)v.findViewById(R.id.itemPrice);
  
                 MessageDetails msg = _data.get(position);
                 subView.setText(msg.sub);    
                 subValueView.setText(msg.subValue.toString());             
  
              return v; 
      }
      }
  
      public class MessageDetails {
          String sub, description;
          Float subValue;
  
          public String getSub() {
              return sub;
          }
  
          public void setSub(String sub) {
              this.sub = sub;
          }
  
          public Float getSubValue() {
              return subValue;
          }
  
          public void setSubValue(Float subValue) {
              this.subValue = subValue;
          }
  
          public String getDescription() {
              return description;
          }
  
          public void setDescription(String description) {
              this.description = description;
          }
      }
  }
  </code></pre>
  
  <p>And my activity that is called (Extends Activity):</p>
  
  <pre><code>public class purchase extends Activity {
  
      Button Btnpurchase;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
  
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          setContentView(R.layout.purchase);
          Btnpurchase = (Button) findViewById(R.id.btnPurchase);
      }
  
  }
  </code></pre>
  
  <p>And my logcat:</p>
  
  <pre><code>07-04 23:35:46.318: E/AndroidRuntime(7924): FATAL EXCEPTION: main
  07-04 23:35:46.318: E/AndroidRuntime(7924): java.lang.NullPointerException
  07-04 23:35:46.318: E/AndroidRuntime(7924):     at android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:1576)
  07-04 23:35:46.318: E/AndroidRuntime(7924):     at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1617)
  07-04 23:35:46.318: E/AndroidRuntime(7924):     at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:481)
  07-04 23:35:46.318: E/AndroidRuntime(7924):     at com.actionbarsherlock.app.SherlockFragmentActivity.onSaveInstanceState(SherlockFragmentActivity.java:127)
  07-04 23:35:46.318: E/AndroidRuntime(7924):     at android.app.Activity.performSaveInstanceState(Activity.java:1155)
  07-04 23:35:46.318: E/AndroidRuntime(7924):     at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1216)
  07-04 23:35:46.318: E/AndroidRuntime(7924):     at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3258)
  07-04 23:35:46.318: E/AndroidRuntime(7924):     at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3318)
  07-04 23:35:46.318: E/AndroidRuntime(7924):     at android.app.ActivityThread.access$900(ActivityThread.java:156)
  07-04 23:35:46.318: E/AndroidRuntime(7924):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
  07-04 23:35:46.318: E/AndroidRuntime(7924):     at android.os.Handler.dispatchMessage(Handler.java:99)
  07-04 23:35:46.318: E/AndroidRuntime(7924):     at android.os.Looper.loop(Looper.java:137)
  07-04 23:35:46.318: E/AndroidRuntime(7924):     at android.app.ActivityThread.main(ActivityThread.java:5233)
  07-04 23:35:46.318: E/AndroidRuntime(7924):     at java.lang.reflect.Method.invokeNative(Native Method)
  07-04 23:35:46.318: E/AndroidRuntime(7924):     at java.lang.reflect.Method.invoke(Method.java:511)
  07-04 23:35:46.318: E/AndroidRuntime(7924):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
  07-04 23:35:46.318: E/AndroidRuntime(7924):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
  07-04 23:35:46.318: E/AndroidRuntime(7924):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>