in my app i want create a CustomCalendarView for decorate a date (simple change background on a specific list of days). (i dont want use third part component). my fragment.xml is simple:

 <com.example.gestionespese.ui.home.CustomCalendarView
    android:id="@+id/calendarView"
    android:layout_width="377dp"
    android:layout_height="338dp"
    android:layout_marginStart="31dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="31dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.464"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

my CustomCalendarView is now very simple just for test if work it:

class CustomCalendarView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : CalendarView(context, attrs, defStyleAttr) {}

on my HomeFragment.kt i use it in this mode:

val calendar: CustomCalendarView =binding.calendarView

but at start i have this error:

java.lang.NullPointerException: Attempt to invoke virtual method 'void 
android.graphics.drawable.Drawable.setBounds(int, int, int, int)' on a null object 
reference

onDraw call onDraw of parentClass CalendarView?

any tips? Regards

0

There are 0 best solutions below