Butterknife库不使用HoloEverywhere / Android bootstrap

时间:2014-04-03 12:42:03

标签: android android-holo-everywhere holoeverywhere android-bootstrap butterknife

我目前正在编写Android Bootstrap应用程序,我希望新的DataPickers能够使用新的小部件,而不必担心移植到2.1+ 所以我使用HoloEveryWhere库。我也使用带有Butterknife库的Android Bootstrap

当我调试时,我得到了这个异常

E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{nl.webridge.whtsnxt.debug/nl.webridge.whtsnxt.authenticator.BootstrapAuthenticatorActivity}: butterknife.ButterKnife$UnableToInjectException: Unable to inject views for nl.webridge.whtsnxt.authenticator.BootstrapAuthenticatorActivity@40619210
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
            at android.app.ActivityThread.access$1500(ActivityThread.java:117)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:130)
            at android.app.ActivityThread.main(ActivityThread.java:3687)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:507)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: butterknife.ButterKnife$UnableToInjectException: Unable to inject views for nl.webridge.whtsnxt.authenticator.BootstrapAuthenticatorActivity@40619210
            at butterknife.ButterKnife.inject(ButterKnife.java:176)
            at butterknife.ButterKnife.inject(ButterKnife.java:104)
            at nl.webridge.whtsnxt.authenticator.BootstrapAuthenticatorActivity.onCreate(BootstrapAuthenticatorActivity.java:140)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
            at android.app.ActivityThread.access$1500(ActivityThread.java:117)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:130)
            at android.app.ActivityThread.main(ActivityThread.java:3687)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:507)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:507)
            at butterknife.ButterKnife.inject(ButterKnife.java:171)
            at butterknife.ButterKnife.inject(ButterKnife.java:104)
            at nl.webridge.whtsnxt.authenticator.BootstrapAuthenticatorActivity.onCreate(BootstrapAuthenticatorActivity.java:140)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
            at android.app.ActivityThread.access$1500(ActivityThread.java:117)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:130)
            at android.app.ActivityThread.main(ActivityThread.java:3687)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:507)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.ClassCastException: org.holoeverywhere.widget.AutoCompleteTextView
            at nl.webridge.whtsnxt.authenticator.BootstrapAuthenticatorActivity$$ViewInjector.inject(BootstrapAuthenticatorActivity$$ViewInjector.java:14)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:507)

我认为我的应用中使用的HoloEverywhere活动存在问题。

例如我使用import org.holoeverywhere.app.Activity;在我的所有活动课程中。

但Butterknife使用android.app.Activity;问题是,我无法在Butterknife中更改代码以使用HoloEverywhere中的Activity。

请告诉我你对此的看法我使用最新版的Butterknife和HoloEveryWhere。

3 个答案:

答案 0 :(得分:1)

尝试在AndroidManifest.xml中设置holo主题:

<application
     android:theme="@style/Holo.Theme.NoActionBar.Fullscreen"

或者可能只是发生问题的活动(也在清单中)

<activity
     android:theme="@style/Holo.Theme.NoActionBar.Fullscreen"

当然在你的java类中,如果组件被定义为xml布局中的holo组件,那么在你的java类中你必须像你一样从holo库中导入该组件:

  import org.holoeverywhere.app.Activity

  import org.holoeverywhere. whatever  (like button, switch, whatever)

答案 1 :(得分:0)

检查@InjectView的类型是否正确。

我已使用ImageView代替LinearLayout

答案 2 :(得分:0)

同时检查您是否未正确使用其他ButterKnife的注射注释。我为RecyclerView使用了 @OnItemClick 注释,这导致了RuntimeException。