我在尝试使用https://github.com/npanigrahy/Custom-Calendar-View中的日历来扩展此布局时遇到异常。
例外情况是:

 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

以下是我的活动:
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
    }
}

这是我的清单:
<?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>

我的布局很简单:
<?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>

我的日志显示了异常:
                  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

我为什么要做这个例外?

最佳答案

确保此位置有customcalendarviewcom.stacktips.view.CustomCalendarView
错误可能是因为您没有位于com.stacktips.view.customcalendarview位置的customcalendarview类。如果您将它放在不同的位置,那么您应该在XML中放在该位置。

08-27 20:10