{"record":{"id":"6aa00bdac7fd940b","repo":"huanghaibin-dev/CalendarView","slug":"e-printstacktrace-6aa00b","errorCode":null,"errorMessage":"e.printStackTrace()","messagePattern":"e\\.printStackTrace\\(\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"calendarview/src/main/java/com/haibin/calendarview/WeekViewPager.java","lineNumber":461,"sourceCode":"        @Override\n        public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {\n            return view.equals(object);\n        }\n\n        @NonNull\n        @Override\n        public Object instantiateItem(@NonNull ViewGroup container, int position) {\n            Calendar calendar = CalendarUtil.getFirstCalendarStartWithMinCalendar(mDelegate.getMinYear(),\n                    mDelegate.getMinYearMonth(),\n                    mDelegate.getMinYearDay(),\n                    position + 1,\n                    mDelegate.getWeekStart());\n            BaseWeekView view;\n            try {\n                Constructor constructor = mDelegate.getWeekViewClass().getConstructor(Context.class);\n                view = (BaseWeekView) constructor.newInstance(getContext());\n            } catch (Exception e) {\n                e.printStackTrace();\n                return new DefaultWeekView(getContext());\n            }\n            view.mParentLayout = mParentLayout;\n            view.setup(mDelegate);\n            view.setup(calendar);\n            view.setTag(position);\n            view.setSelectedCalendar(mDelegate.mSelectedCalendar);\n            container.addView(view);\n            return view;\n        }\n\n        @Override\n        public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {\n            BaseWeekView view = (BaseWeekView) object;\n            view.onDestroy();\n            container.removeView(view);\n        }\n    }","sourceCodeStart":443,"sourceCodeEnd":479,"githubUrl":"https://github.com/huanghaibin-dev/CalendarView/blob/f5479ea3baefdbba2453cea19a208eca83baeb9e/calendarview/src/main/java/com/haibin/calendarview/WeekViewPager.java#L443-L479","documentation":"WeekViewPager.instantiateItem reflectively constructs the configured custom week view class. On any reflection failure it prints the stack trace and falls back to DefaultWeekView, so the calendar works but the custom week view is silently skipped.","triggerScenarios":"Class from app:calendar_week_view_class has no public (Context) constructor, is a non-static inner class, throws in its constructor, or is inaccessible due to obfuscation.","commonSituations":"Custom BaseWeekView subclass written as inner class; constructor relying on Activity context; release builds with R8 removing/rename-ing the class; class name typo in XML.","solutions":["Provide a public constructor accepting Context and avoid Activity casts inside it.","Make the class public and top-level (or static).","Read logcat for the underlying NoSuchMethodException/InvocationTargetException.","Add a keep rule preserving the constructor.","Verify the XML attribute names the exact fully-qualified class."],"exampleFix":"// before\npublic class MyWeekView extends BaseWeekView {\n    MyWeekView(Context c) { super(c); } // package-private, reflection fails\n}\n// after\npublic class MyWeekView extends BaseWeekView {\n    public MyWeekView(Context context) { super(context); }\n}","handlingStrategy":"fallback","validationCode":"Class<?> cls = Class.forName(\"com.example.CustomWeekView\");\ncls.getConstructor(Context.class);\n","typeGuard":"static boolean instantiableWeekView(Class<?> cls) {\n    try {\n        return BaseWeekView.class.isAssignableFrom(cls)\n            && cls.getConstructor(Context.class) != null;\n    } catch (NoSuchMethodException e) { return false; }\n}","tryCatchPattern":"// Library falls back to DefaultWeekView; preflight in app code:\ntry {\n    CustomWeekView.class.getConstructor(Context.class).newInstance(context);\n} catch (Throwable t) {\n    Log.w(\"Calendar\", \"CustomWeekView failed, default week view will render\", t);\n}","preventionTips":["Public top-level class with a public (Context) constructor.","No Activity casting or throwing code in the constructor.","Keep rules for release builds; test week paging in a minified build.","Confirm XML attribute matches the class after every rename."],"tags":["android","reflection","fallback","week-view"],"backgroundTag":"class-not-found","analyzedSha":"f5479ea3baefdbba2453cea19a208eca83baeb9e","analyzedAt":"2026-09-11T10:11:54.823Z","contentChangedAt":"2026-09-11T10:11:54.823Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}