This Question have 3 answers right now.

Android error inflating calendar layout

Question!

I am getting an exception when trying inflate this layout with a calendar from https://github.com/npanigrahy/Custom-Calendar-View.

The exception is:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{net.simplifiedcoding.androidloginlogout/net.simplifiedcoding.androidloginlogout.MarcaHoraActivity}: android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class com.stacktips.view.CustomCalendarView

Here is my activity:

public class MarcaHoraActivity extends AppCompatActivity  {
    CustomCalendarView calendarView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simple_calendar);// -->Exception is here
    }
}

Here is my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="net.simplifiedcoding.androidloginlogout" >

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <activity android:name=".LoginActivity" android:theme="@style/AppTheme.Dark">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".ProfileActivity" >
        </activity>
        <activity android:name=".SignupActivity" android:theme="@style/AppTheme.Dark" />
        <activity android:name=".HospGridViewActivity" android:theme="@style/AppTheme.Dark" />
        <activity android:name=".DetailsActivity" android:theme="@style/AppTheme.Dark" />
        <activity android:name=".EspecGridViewActivity" android:theme="@style/AppTheme.Dark" />
        <activity android:name=".MarcaHoraActivity" android:theme="@style/AppTheme.Dark" />
    </application>

</manifest>

My layout is very simple:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="net.simplifiedcoding.androidloginlogout.MarcaHoraActivity">


    <com.stacktips.view.CustomCalendarView
        android:id="@+id/calendar_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"/>

</LinearLayout>

My log showing the exception:

                  E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: net.simplifiedcoding.androidloginlogout, PID: 4430
                  java.lang.RuntimeException: Unable to start activity ComponentInfo{net.simplifiedcoding.androidloginlogout/net.simplifiedcoding.androidloginlogout.MarcaHoraActivity}: android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class com.stacktips.view.CustomCalendarView
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                      at android.app.ActivityThread.-wrap11(ActivityThread.java)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:148)
                      at android.app.ActivityThread.main(ActivityThread.java:5417)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                   Caused by: android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class com.stacktips.view.CustomCalendarView
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                      at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:257)
                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
                      at net.simplifiedcoding.androidloginlogout.MarcaHoraActivity.onCreate(MarcaHoraActivity.java:32)
                      at android.app.Activity.performCreate(Activity.java:6237)
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                      at android.os.Looper.loop(Looper.java:148) 
                      at android.app.ActivityThread.main(ActivityThread.java:5417) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                   Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class com.stacktips.view.CustomCalendarView
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
                      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                      at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:257) 
                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) 
                      at net.simplifiedcoding.androidloginlogout.MarcaHoraActivity.onCreate(MarcaHoraActivity.java:32) 
                      at android.app.Activity.performCreate(Activity.java:6237) 
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                      at android.os.Looper.loop(Looper.java:148) 
                      at android.app.ActivityThread.main(ActivityThread.java:5417) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                   Caused by: java.lang.ClassNotFoundException: Didn't find class "com.stacktips.view.CustomCalendarView" on path: DexPathList[[zip file "/data/app/net.simplifiedcoding.androidloginlogout-1/base.apk"],nativeLibraryDirectories=[/data/app/net.simplifiedcoding.androidloginlogout-1/lib/x86, /vendor/lib, /system/lib]]
                      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                      at android.view.LayoutInflater.createView(LayoutInflater.java:583)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
                      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                      at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:257) 
                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) 
                      at net.simplifiedcoding.androidloginlogout.MarcaHoraActivity.onCreate(MarcaHoraActivity.java:32) 
                      at android.app.Activity.performCreate(Activity.java:6237) 
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                      at android.os.Looper.loop(Looper.java:148) 
                      at android.app.ActivityThread.main(ActivityThread.java:5417) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                    Suppressed: java.lang.ClassNotFoundException: Didn't find class "com.stacktips.view.CustomCalendarView" on path: DexPathList[[dex file "/data/data/net.simplifiedcoding.androidloginlogout/files/instant-run/dex/slice-support-annotations-23.1.0_23e8f30513101570f33330912f51dcf82529e185-classes.dex", dex file "/data/data/net.simplifiedcoding.androidloginlogout/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/net.simplifiedcoding.androidloginlogout/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/net.simplifiedcoding.androidloginlogout/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/net.simplifiedcoding.androidloginlogout/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/net.simplifiedcoding.androidloginlogout/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/net.simplifiedcoding.androidloginlogout/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/net.simpl
I/Process: Sending signal. PID: 4430 SIG: 9

Why am I doing this exception?



Answers

Make sure you have CustomCalendarView at this location com.stacktips.view.CustomCalendarView.

The error is possibly because you donot have the CustomCalendarView class at the location com.stacktips.view.CustomCalendarView. If you have it in a different location you should have that location in your xml.



I will suggest to implement one constructor for unsigned long long it.

The reason is: execute below code. Code will not compile due to ambiguity.

Then remove the int constructor and build again. Now the code will compile and execute successfully.

#include <iostream>

class myClass {
    private:
        unsigned long long int words;

    public:

    myClass(int i)
    {
        std::cout<<"in Int constructor"<<std::endl;

    }

    myClass(long long int i)
    {

        std::cout<<"in long constructor"<<std::endl;
    }

};

int main()
{
    myClass m(10000000000);    

    return 0;   
}


You need a logical condition in the while. Perhaps

program.toUpperCase().equals("Y")
By : nicomp


Video about Android error inflating calendar layout