0

Here is my code, it's not showing any error. When i try to run it's getting closed, ClassCastException.

NOTE:THE SAME CODE IS WORKING WHEN EXTENDING TO SherlockFragment

public class EventsFeatured extends SherlockFragmentActivity {
TextView cal;
View view;

int year;
int month;
int day;


public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.events_featured, container, false);
    iniitialize();

    return view;
}

private void iniitialize() {
    // TODO Auto-generated method stub
    Calendar t = Calendar.getInstance();
    year = t.get(Calendar.YEAR);
    month = t.get(Calendar.MONTH);
    day = t.get(Calendar.DAY_OF_MONTH);
    cal = (TextView) view.findViewById(R.id.tvCalendar);
    cal.setText(new StringBuilder()
    .append(month + 1).append("-").append(day).append("-")
    .append(year).append(" "));
}
    }

enter image description here

enter image description here

DroidLearner
  • 2,115
  • 5
  • 31
  • 50

1 Answers1

0

Your code fails because in your TabsAdapter's getItem() method you're trying to create a Fragment(SherlockFragment) from a class that isn't a Fragment (as the getItem() method expects), that class is a SherlockFragmentActivity.

Why do you need EventsFeatured to extend SherlockFragmentActivity when from the looks of it(and how you use it) that class should be extending SherlockFragment? For example you have the onCreateView() method in EventsFeatured which it's just a simple method, it's not the callback method of a Fragment in which the Fragment's view is created.

If you need activities as tabs you need to use a TabActivity(but, which you shouldn't use as it's deprecated).

user
  • 86,916
  • 18
  • 197
  • 190