{"record":{"id":"1fffa5dd3dfed044","repo":"huanghaibin-dev/CalendarView","slug":"e-printstacktrace-1fffa5","errorCode":null,"errorMessage":"e.printStackTrace()","messagePattern":"e\\.printStackTrace\\(\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"calendarview/src/main/java/com/haibin/calendarview/CalendarViewDelegate.java","lineNumber":560,"sourceCode":"        array.recycle();\n        init();\n    }\n\n    private void init() {\n        mCurrentDate = new Calendar();\n        Date d = new Date();\n        mCurrentDate.setYear(CalendarUtil.getDate(\"yyyy\", d));\n        mCurrentDate.setMonth(CalendarUtil.getDate(\"MM\", d));\n        mCurrentDate.setDay(CalendarUtil.getDate(\"dd\", d));\n        mCurrentDate.setCurrentDay(true);\n        LunarCalendar.setupLunarCalendar(mCurrentDate);\n        setRange(mMinYear, mMinYearMonth, mMaxYear, mMaxYearMonth);\n\n        try {\n            mWeekBarClass = TextUtils.isEmpty(mWeekBarClassPath) ?\n                    mWeekBarClass = WeekBar.class : Class.forName(mWeekBarClassPath);\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n\n        try {\n            mYearViewClass = TextUtils.isEmpty(mYearViewClassPath) ?\n                    mYearViewClass = DefaultYearView.class : Class.forName(mYearViewClassPath);\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n        try {\n            mMonthViewClass = TextUtils.isEmpty(mMonthViewClassPath) ?\n                    DefaultMonthView.class : Class.forName(mMonthViewClassPath);\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n        try {\n            mWeekViewClass = TextUtils.isEmpty(mWeekViewClassPath) ?\n                    DefaultWeekView.class : Class.forName(mWeekViewClassPath);\n        } catch (Exception e) {","sourceCodeStart":542,"sourceCodeEnd":578,"githubUrl":"https://github.com/huanghaibin-dev/CalendarView/blob/f5479ea3baefdbba2453cea19a208eca83baeb9e/calendarview/src/main/java/com/haibin/calendarview/CalendarViewDelegate.java#L542-L578","documentation":"In the CalendarViewDelegate constructor, Class.forName resolves the custom WeekBar class from app:calendar_week_bar_view. If the class path string names a class not on the classpath, Class.forName throws and printStackTrace hides it, leaving mWeekBarClass as the assignment result of the ternary chain rather than the intended custom class.","triggerScenarios":"app:calendar_week_bar_view set to a misspelled or renamed fully-qualified class name; the class exists in a different module/dependency not included; class removed by shrinking tools.","commonSituations":"Copy-pasting a config from a tutorial with a package name that doesn't match the project; refactoring a package without updating XML attributes; release builds with ProGuard stripping the view class.","solutions":["Fix app:calendar_week_bar_view in XML to the exact fully-qualified class name (package + class).","Confirm the class exists and is public in a module included as a dependency.","Add a keep rule so shrinking tools don't remove/rename the class.","Check logcat for the ClassNotFoundException stack trace to confirm.","If no custom week bar is needed, remove the attribute so the default WeekBar is used."],"exampleFix":"// before\napp:calendar_week_bar_view=\"com.example.views.WeekBarView\"\n// after (class moved to com.example.ui)\napp:calendar_week_bar_view=\"com.example.ui.WeekBarView\"","handlingStrategy":"validation","validationCode":"// Validate the XML attribute value before inflating the CalendarView:\nString path = \"com.example.MyWeekBar\";\nClass<?> cls = Class.forName(path); // will throw ClassNotFoundException early if wrong\nif (!WeekBar.class.isAssignableFrom(cls)) throw new IllegalStateException(\"Not a WeekBar\");\n","typeGuard":"static boolean isLoadableWeekBar(String path) {\n    try { return WeekBar.class.isAssignableFrom(Class.forName(path)); }\n    catch (Throwable t) { return false; }\n}","tryCatchPattern":"// Library swallows the exception; wrap your own initialization to detect it:\ntry {\n    setContentView(R.layout.activity_calendar);\n} finally {\n    if (calendarView.getWeekBar() == null) {\n        Log.e(\"Calendar\", \"Custom week bar failed to load; check calendar_week_bar_view\");\n    }\n}","preventionTips":["Copy the fully-qualified class name from the class file/package declaration, never by hand.","After renaming a package, grep XML/attrs for the old package name.","Enable -keep rules for classes referenced from XML.","Verify in a release build with minification enabled before shipping."],"tags":["android","reflection","class-not-found","xml-config"],"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"}