1

This is an odd one. Yesterday I added the following library as a dependency to my module level gradle in a simple empty default android project:

https://github.com/recruit-mp/LightCalendarView

I added the view to the activities layout file:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.thomascoook.testbed.MainActivity">

    <jp.co.recruit_mp.android.lightcalendarview.MonthView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    </jp.co.recruit_mp.android.lightcalendarview.MonthView>

</android.support.constraint.ConstraintLayout>

And ran the application on a Nexus 5X API 25 emulator. It worked, the month view displayed just like on the GitHub.

Then today, I'm working from home. I've done exactly the same thing on my home environment and I'm getting a NoSuchMethodException when the activities view is inflated. The missing method is a constructor in the MonthView class. Here is the full stack trace:

Process: com.thomascoook.testbed, PID: 4539
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.thomascoook.testbed/com.thomascoook.testbed.MainActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class jp.co.recruit_mp.android.lightcalendarview.MonthView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class jp.co.recruit_mp.android.lightcalendarview.MonthView
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class jp.co.recruit_mp.android.lightcalendarview.MonthView
Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
at java.lang.Class.getConstructor0(Class.java:2204)
at java.lang.Class.getConstructor(Class.java:1683)
at android.view.LayoutInflater.createView(LayoutInflater.java:618)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.thomascoook.testbed.MainActivity.onCreate(MainActivity.kt:10)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

When I look at the source code for the offending class in the library, MonthView, I can see that it is indeed missing the required constructors:

/*
 * Copyright (C) 2016 RECRUIT MARKETING PARTNERS CO., LTD.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package jp.co.recruit_mp.android.lightcalendarview

import android.content.Context
import android.view.ViewGroup
import android.widget.LinearLayout
import jp.co.recruit_mp.android.lightcalendarview.accent.Accent
import java.util.*

/**
 * 月カレンダーを表示する {@link LinearLayout}
 * Created by masayuki-recruit on 8/19/16.
 */
class MonthView(context: Context, private val settings: CalendarSettings, var month: Date) : LinearLayout(context), DayLayout.Callback {

    internal var callback: Callback? = null

    private val weekDayLayout: WeekDayLayout
    private val dayLayout: DayLayout

    init {
        orientation = LinearLayout.VERTICAL

        weekDayLayout = WeekDayLayout(context, settings)
        addView(weekDayLayout, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))

        dayLayout = DayLayout(context, settings, month).apply { callback = this@MonthView }
        addView(dayLayout, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
    }

    override fun onDateSelected(date: Date) {
        callback?.onDateSelected(date)
    }

    fun setSelectedDate(date: Date) {
        dayLayout.setSelectedDay(date)
    }

    fun setAccents(date: Date, accents: Collection<Accent>) = dayLayout.let {
        it.getDayView(date)?.setAccents(accents)
        it.invalidateDayViews()
    }

    fun setAccents(map: Map<Date, Collection<Accent>>) {
        map.forEach { it ->
            val (date, accents) = it
            dayLayout.getDayView(date)?.setAccents(accents)
        }
        dayLayout.invalidateDayViews()
    }

    interface Callback {
        fun onDateSelected(date: Date)
    }

    override fun toString(): String = "MonthView(${month})"
}

How was this working yesterday? There have been no changes to the source code of the library between the 2 times. The only possible thing that may be different is my home environment vs my work environment (i.e. my android studio setup).

Thomas Cook
  • 4,371
  • 2
  • 25
  • 42
  • Is anyone able to reproduce in a blank android studio project configured with Kotlin? It takes 2 minutes if you have android studio installed, I am unable to validate as I only have one environment at home. – Thomas Cook Nov 08 '17 at 13:11

0 Answers0