title: Fragment java.lang.ClassCastException Error
body: <p>How to cast Fragment activity?</p>
  
  <p>Actually I am trying to Open through button on <strong>Activity</strong> to <strong>Fragment Activity</strong></p>
  
  <p><strong>Android MainFest :</strong></p>
  
  <pre><code>&lt;activity android:name="parth.any.ttb.Fragment_1"/&gt;
  </code></pre>
  
  <p><strong>LogCat:</strong></p>
  
  <pre><code>12-04 15:22:43.132: E/AndroidRuntime(25873): FATAL EXCEPTION: main
  12-04 15:22:43.132: E/AndroidRuntime(25873): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{parth.any.ttb/parth.any.ttb.Fragment_1}: java.lang.ClassCastException: parth.any.ttb.Fragment_1
  12-04 15:22:43.132: E/AndroidRuntime(25873):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
  12-04 15:22:43.132: E/AndroidRuntime(25873):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
  12-04 15:22:43.132: E/AndroidRuntime(25873):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
  12-04 15:22:43.132: E/AndroidRuntime(25873):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
  12-04 15:22:43.132: E/AndroidRuntime(25873):    at android.os.Handler.dispatchMessage(Handler.java:99)
  12-04 15:22:43.132: E/AndroidRuntime(25873):    at android.os.Looper.loop(Looper.java:130)
  12-04 15:22:43.132: E/AndroidRuntime(25873):    at android.app.ActivityThread.main(ActivityThread.java:3687)
  12-04 15:22:43.132: E/AndroidRuntime(25873):    at java.lang.reflect.Method.invokeNative(Native Method)
  12-04 15:22:43.132: E/AndroidRuntime(25873):    at java.lang.reflect.Method.invoke(Method.java:507)
  12-04 15:22:43.132: E/AndroidRuntime(25873):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
  12-04 15:22:43.132: E/AndroidRuntime(25873):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
  12-04 15:22:43.132: E/AndroidRuntime(25873):    at dalvik.system.NativeStart.main(Native Method)
  12-04 15:22:43.132: E/AndroidRuntime(25873): Caused by: java.lang.ClassCastException: parth.any.ttb.Fragment_1
  12-04 15:22:43.132: E/AndroidRuntime(25873):    at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
  12-04 15:22:43.132: E/AndroidRuntime(25873):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565
  </code></pre>
  
  <p>)</p>
  
  <p>Here is Both the class codes:
  <strong>Edit: NewTransaction.java</strong></p>
  
  <pre><code>startActivity(new Intent(getApplicationContext(), Fragment_1.class));
  </code></pre>
  
  <p><strong>Fragment_1.java</strong></p>
  
  <pre><code>public class Fragment_1 extends Fragment implements OnClickListener {
          TextView Home;
          Animation animMove;
  
          // slide menu items
          private String[] spinMenuTitles;
          private TypedArray spinMenuIcons;
          private Button Add_New;     
          private ArrayList&lt;TypeCustomSpinnerItem&gt; spinDropItems;
          private TypeSpinnerListAdapter adapter;
  
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
          View view = inflater.inflate(R.layout.fragment_1, null);
          Home = (TextView)view.findViewById(R.id.home);
          Add_New = (Button)view.findViewById(R.id.add_new);
          Add_New.setOnClickListener(this);
  
          animMove = AnimationUtils.loadAnimation(getActivity(),R.anim.move);
          Home.startAnimation(animMove);
  
                  // load type spin menu items
                  spinMenuTitles = getResources().getStringArray(R.array.type_spinner_items);
  
                  // type spinner icons from resources
                  spinMenuIcons = getResources().obtainTypedArray(R.array.type_spinner_icons);
  
                  spinDropItems = new ArrayList&lt;TypeCustomSpinnerItem&gt;();
  
                  // adding type spinner items to array
                  int i;
                  for(i=0;i&lt;=9;i++)
                  {
                  spinDropItems.add(new TypeCustomSpinnerItem(spinMenuTitles[i], spinMenuIcons.getResourceId(i, -1)));
                  }
                  // Recycle the typed array
                  spinMenuIcons.recycle();
  
                  Spinner mySpinner = (Spinner)view.findViewById(R.id.spinner1);
                  adapter = new TypeSpinnerListAdapter(getActivity(),spinDropItems);
                  mySpinner.setAdapter(adapter);
  
          return view;
      }
  
      @Override
      public void onClick(View v) {
          // TODO Auto-generated method stub
          switch (v.getId()) {
          case R.id.add_new:
              Intent addintent = new Intent(getActivity() , AddNewTransaction.class);
              startActivity(addintent);
              break;
  
      }
      }
  }
  </code></pre>