使用额外的库

时间:2016-03-28 18:13:06

标签: android xml

我正在尝试使用自定义日历。 (通过xml-markup显示)。但是应用程序崩溃了。可能是什么原因?我所做的就是写在这里。由Gradle手动插入build.gradle。我和其他类似的库有同样的问题,已经尝试过使用5-6个库。 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.denis.myplans.NewNoteActivity">

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

</RelativeLayout>

来自错误日志:

  03-28 21:30:36.222 7338-7338/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                 Process: com.example.denis.myplans, PID: 7338
                                                 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.denis.myplans/com.example.denis.myplans.MainActivity}: android.view.InflateException: Binary XML file line #16: Error inflating class com.imanoweb.calendarview.CustomCalendarView
                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2521)
                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2601)
                                                     at android.app.ActivityThread.access$800(ActivityThread.java:178)
                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
                                                     at android.os.Handler.dispatchMessage(Handler.java:111)
                                                     at android.os.Looper.loop(Looper.java:194)
                                                     at android.app.ActivityThread.main(ActivityThread.java:5637)
                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                     at java.lang.reflect.Method.invoke(Method.java:372)
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
                                                  Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class com.imanoweb.calendarview.CustomCalendarView
                                                     at android.view.LayoutInflater.createView(LayoutInflater.java:633)
                                                     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
                                                     at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
                                                     at android.view.LayoutInflater.parseInclude(LayoutInflater.java:916)
                                                     at android.view.LayoutInflater.rInflate(LayoutInflater.java:802)
                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
                                                     at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
                                                     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                                                     at com.example.denis.myplans.MainActivity.onCreate(MainActivity.java:19)
                                                     at android.app.Activity.performCreate(Activity.java:6112)
                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2601) 
                                                     at android.app.ActivityThread.access$800(ActivityThread.java:178) 
                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470) 
                                                     at android.os.Handler.dispatchMessage(Handler.java:111) 
                                                     at android.os.Looper.loop(Looper.java:194) 
                                                     at android.app.ActivityThread.main(ActivityThread.java:5637) 
                                                     at java.lang.reflect.Method.invoke(Native Method) 
                                                     at java.lang.reflect.Method.invoke(Method.java:372) 
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960) 
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
                                                  Caused by: java.lang.reflect.InvocationTargetException
                                                     at java.lang.reflect.Constructor.newInstance(Native Method)
                                                     at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
                                                     at android.view.LayoutInflater.createView(LayoutInflater.java:607)
                                                     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
                                                     at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
                                                     at android.view.LayoutInflater.parseInclude(LayoutInflater.java:916) 
                                                     at android.view.LayoutInflater.rInflate(LayoutInflater.java:802) 
                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
                                                     at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276) 
                                                     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                                                     at com.example.denis.myplans.MainActivity.onCreate(MainActivity.java:19) 
                                                     at android.app.Activity.performCreate(Activity.java:6112) 
                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112) 
                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468) 
                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2601) 
                                                     at android.app.ActivityThread.access$800(ActivityThread.java:178) 
                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470) 
                                                     at android.os.Handler.dispatchMessage(Handler.java:111) 
                                                     at android.os.Looper.loop(Looper.java:194) 
                                                     at android.app.ActivityThread.main(ActivityThread.java:5637) 
                                                     at java.lang.reflect.Method.invoke(Native Method) 
                                                     at java.lang.reflect.Method.invoke(Method.java:372) 
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960) 
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
                                                  Caused by: java.lang.StringIndexOutOfBoundsException: length=2; regionStart=0; regionLength=3
                                                     at java.lang.String.startEndAndLength(String.java:504)
                                                     at java.lang.String.substring(String.java:1333)
                                                     at com.imanoweb.calendarview.CustomCalendarView.initializeWeekLayout(CustomCalendarView.java:171)
                                                     at com.imanoweb.calendarview.CustomCalendarView.refreshCalendar(CustomCalendarView.java:356)
                                                     at com.imanoweb.calendarview.CustomCalendarView.initializeCalendar(CustomCalendarView.java:132)
                                                     at com.imanoweb.calendarview.CustomCalendarView.<init>(CustomCalendarView.java:74)
                                                     at java.lang.reflect.Constructor.newInstance(Native Method) 
                                                     at java.lang.reflect.Constructor.newInstance(Constructor.java:288) 
                                                     at android.view.LayoutInflater.createView(LayoutInflater.java:607) 
                                                     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
                                                     at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
                                                     at android.view.LayoutInflater.parseInclude(LayoutInflater.java:916) 
                                                     at android.view.LayoutInflater.rInflate(LayoutInflater.java:802) 
                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
                                                     at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276) 
                                                     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                                                     at com.example.denis.myplans.MainActivity.onCreate(MainActivity.java:19) 
                                                     at android.app.Activity.performCreate(Activity.java:6112) 
                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112) 
                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468) 
                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2601) 
                                                     at android.app.ActivityThread.access$800(ActivityThread.java:178) 
                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470) 
                                                     at android.os.Handler.dispatchMessage(Handler.java:111) 
                                                     at android.os.Looper.loop(Looper.java:194) 
                                                     at android.app.ActivityThread.main(ActivityThread.java:5637) 
                                                     at java.lang.reflect.Method.invoke(Native Method) 
                                                     at java.lang.reflect.Method.invoke(Method.java:372)

的build.gradle

 apply plugin: 'com.android.application'

    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.2"

        defaultConfig {
            applicationId "com.example.denis.myplans"
            minSdkVersion 19
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:23.2.1'
        compile 'com.android.support:design:23.2.1'
        compile 'com.github.npanigrahy:Custom-Calendar-View:v1.0'
    }

MainActivity.java

    package com.example.denis.myplans;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;

import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        final Intent intNewNote = new Intent(this, NewNoteActivity.class);
        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        assert fab != null;

        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(intNewNote);

            }
        });
    }

1 个答案:

答案 0 :(得分:0)

要使用这个库你需要阅读如何实现,首先需要在build.gradle上添加Jitpack存储库。

productMenu.add('.navlistitem > a:contains("Products")').hover(function(){...

你应该添加这个

apply plugin: 'com.android.application'

在您的Maven存储库上,依赖性需求如下所示。

repositories {
maven { url "https://jitpack.io" }
}

之后它应该可以工作。