Error: Cannot Find Symbol Method Getsupportactionbar(),findviewbyid(int),getapplicationcontext()
So I have this code inside my ScheduleFragment in which my objective was to view a simple calendar viewer. But unfortunately, it gets an error mentioned in the title. Even if I cha
Solution 1:
In fragments, you can not directly call findViewById()
and have to use the view that you just inflated and call findViewById()
on it.
So your onCreateView code will be,
@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragmentViewv= inflater.inflate(R.layout.fragment_schedule, container, false);
compactCalendar = (CompactCalendarView) v.findViewById(R.id.compactcalendar_view);
//Make sure that the view inflated above has these view elements which you are trying to initialize
.
.
.
}
Similarly for getApplicationContext()
, you first need to call getContext()
and then call getApplicationContext()
on it
So it becomes,
Contextc= getContext().getApplicationContext();
Same goes for getSupportActionBar();
Solution 2:
In my opinion, you should inflate the view and use view.findViewByID(R.id.id), then call return at the end of the method .
Post a Comment for "Error: Cannot Find Symbol Method Getsupportactionbar(),findviewbyid(int),getapplicationcontext()"