{"record":{"id":"c50705a1fc5509ae","repo":"huanghaibin-dev/CalendarView","slug":"e-printstacktrace-c50705","errorCode":null,"errorMessage":"e.printStackTrace()","messagePattern":"e\\.printStackTrace\\(\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"calendarview/src/main/java/com/haibin/calendarview/YearViewAdapter.java","lineNumber":55,"sourceCode":"    }\n\n\n    final void setYearViewSize(int width, int height) {\n        this.mItemWidth = width;\n        this.mItemHeight = height;\n    }\n\n    @Override\n    RecyclerView.ViewHolder onCreateDefaultViewHolder(ViewGroup parent, int type) {\n        YearView yearView;\n        if (TextUtils.isEmpty(mDelegate.getYearViewClassPath())) {\n            yearView = new DefaultYearView(mContext);\n        } else {\n            try {\n                Constructor constructor = mDelegate.getYearViewClass().getConstructor(Context.class);\n                yearView = (YearView) constructor.newInstance(mContext);\n            } catch (Exception e) {\n                e.printStackTrace();\n                yearView = new DefaultYearView(mContext);\n            }\n        }\n        RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT,\n                RecyclerView.LayoutParams.MATCH_PARENT);\n        yearView.setLayoutParams(params);\n        return new YearViewHolder(yearView, mDelegate);\n    }\n\n    @Override\n    void onBindViewHolder(RecyclerView.ViewHolder holder, Month item, int position) {\n        YearViewHolder h = (YearViewHolder) holder;\n        YearView view = h.mYearView;\n        view.init(item.getYear(), item.getMonth());\n        view.measureSize(mItemWidth, mItemHeight);\n    }\n\n    private static class YearViewHolder extends RecyclerView.ViewHolder {","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/huanghaibin-dev/CalendarView/blob/f5479ea3baefdbba2453cea19a208eca83baeb9e/calendarview/src/main/java/com/haibin/calendarview/YearViewAdapter.java#L37-L73","documentation":"YearViewAdapter.onCreateDefaultViewHolder reflectively instantiates the configured custom year view. On failure it prints the stack trace and falls back to DefaultYearView, so the year picker renders with default styling instead of the user's custom year view.","triggerScenarios":"Class from app:calendar_year_view_class has no public (Context) constructor, is a non-static inner class, throws during construction, or is stripped/renamed by code shrinking.","commonSituations":"Custom YearView written as an Activity inner class; R8 minified release builds without keep rules; constructor expecting an Activity context; wrong XML class path after refactoring.","solutions":["Declare a public constructor taking Context.","Make the class public, top-level or static nested, extending BaseYearView.","Inspect logcat for the printed reflection exception.","Add -keep class com.example.CustomYearView { public <init>(android.content.Context); } to proguard-rules.pro.","Confirm app:calendar_year_view_class matches the exact fully-qualified name."],"exampleFix":"// before\napp:calendar_year_view_class=\"com.app.YearPage\" // class has no (Context) ctor\n// after\n// public class YearPage extends BaseYearView { public YearPage(Context c){super(c);} }\napp:calendar_year_view_class=\"com.app.YearPage\"","handlingStrategy":"fallback","validationCode":"Class<?> cls = Class.forName(\"com.example.CustomYearView\");\ncls.getConstructor(Context.class);\n","typeGuard":"static boolean instantiableYearView(Class<?> cls) {\n    try {\n        return BaseYearView.class.isAssignableFrom(cls)\n            && cls.getConstructor(Context.class) != null;\n    } catch (NoSuchMethodException e) { return false; }\n}","tryCatchPattern":"// Library falls back to DefaultYearView; preflight:\ntry {\n    CustomYearView.class.getConstructor(Context.class).newInstance(context);\n} catch (Throwable t) {\n    Log.w(\"Calendar\", \"CustomYearView failed; DefaultYearView will be used\", t);\n}","preventionTips":["Make the custom year view public with a Context-only constructor.","Add proguard keep rules; verify in release build.","After refactors, re-check app:calendar_year_view_class in XML.","Open the year picker once in CI smoke tests to catch silent fallbacks."],"tags":["android","reflection","fallback","year-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"}