I have a fragment called CalendarFragment. I am getting this error when i tried executing the program. Error:(36, 74) error: incompatible types: CalendarFragment cannot be conve
I suppose your error is indicating the line CalendarEventDataSource dataSource = new CalendarEventDataSource(this);
Try and change this
with either getActivity()
or getActivity().getApplicationContext()
or getActivity().getBaseContext()
.
Also no need for onCreate()
as other have suggested.
A Fragment represents a behavior or a portion of user interface in an Activity.
Call onCreateView
instead of onCreate
. Remove onCreate()
call getActivity() instead of this. getActivity() Return the Activity this fragment is currently associated with.
CalendarEventDataSource dataSource = new CalendarEventDataSource(getActivity());
Problem
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_calendar);
}
This code for Activity . You should use your onCreateView
method .
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.fragment_calendar, container, false);
return rootView;
}
http://developer.android.com/intl/es/guide/components/fragments.html
remove setcontentview
from onCreate
method you already set view in onCreateView