我想将带有素材元素的library导入到我的项目中。 因此,在提到的Github指令中,我已将该依赖项添加到我的成绩文件中:
dependencies {
compile 'com.github.rey5137:material:1.2.1'
}
之后进行Gradle同步。 在下一步中,我将xml添加到我的布局中:
<com.rey.material.widget.Spinner
style="@style/Material.Widget.Spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:rd_style="@style/Material.Drawable.Ripple.Wave"/>
运行应用程序会给我一个问题:
Binary XML file line #35: Binary XML file line #35: Error inflating class com.rey.material.widget.Spinner
我还应该做什么才能正确导入该库?我不知道我错过了什么。
我的xml布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:layout_weight="10"
android:background="#19d1ff">
<TextView android:id="@+id/registration_textview_titel_registrieren"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_gravity="top"
android:layout_marginTop="25dp"
android:background="@drawable/round_corner_textview"
android:text="Registrieren" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:background="#458b00"
android:layout_weight="10" >
<com.rey.material.widget.Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:background="#5e00ff"
android:layout_weight="10" >
</LinearLayout>
</LinearLayout>
堆栈跟踪:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ads.adstimer/com.ads.adstimer.activity.RegistrationActivity}: android.view.InflateException: Binary XML file line #35: Error inflating class com.rey.material.widget.Spinner
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:151)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5254)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #35: Error inflating class com.rey.material.widget.Spinner
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.view.LayoutInflater.createView(LayoutInflater.java:633)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at com.ads.adstimer.fragment.Registration.FragmentRegistration.onCreateView(FragmentRegistration.java:31)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1026)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1207)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1572)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:330)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:511)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.Activity.performStart(Activity.java:6006)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:151)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5254)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at java.lang.reflect.Constructor.newInstance(Native Method)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.view.LayoutInflater.createView(LayoutInflater.java:607)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at com.ads.adstimer.fragment.Registration.FragmentRegistration.onCreateView(FragmentRegistration.java:31)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1026)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1207)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1572)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:330)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:511)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.Activity.performStart(Activity.java:6006)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:151)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5254)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: Caused by: java.lang.NoSuchFieldError: No static field Spinner_android_gravity of type I in class Lcom/rey/material/R$styleable; or its superclasses (declaration of 'com.rey.material.R$styleable' appears in /data/app/com.ads.adstimer-1/base.apk)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at com.rey.material.widget.Spinner.applyStyle(Spinner.java:234)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at com.rey.material.widget.Spinner.init(Spinner.java:149)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at com.rey.material.widget.Spinner.<init>(Spinner.java:128)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at java.lang.reflect.Constructor.newInstance(Native Method)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.view.LayoutInflater.createView(LayoutInflater.java:607)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at com.ads.adstimer.fragment.Registration.FragmentRegistration.onCreateView(FragmentRegistration.java:31)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1026)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1207)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1572)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:330)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:511)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.Activity.performStart(Activity.java:6006)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:151)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5254)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
11-11 11:57:40.026 19707-19707/com.ads.adstimer E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
答案 0 :(得分:2)
试试这个:
打开build.gradle(模块:app)
更改编译'com.github.rey5137:material:1.2.1' 编译'com.github.rey5137:material:1.2.1.6-SNAPSHOT'
然后在应用插件后:'com.android.application',放 存储库{maven {url“https://oss.sonatype.org/content/repositories/snapshots”}}
然后按照Android Studio的建议进行Gradle同步。
我在这个链接中找到了解决方案:
https://github.com/rey5137/material/issues/222
检查一下!