任何人都可以帮我解决Coverflow上的InflateException问题吗?

时间:2015-02-23 06:10:34

标签: android xml coverflow

我是这项技术的新手。我面临InflateException:二进制XML第9行错误。清单文件中添加了活动。问题是什么?

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:pj="http://schemas.android.com/apk/res"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="16dp"
        android:paddingRight="16dp" >

    <com.myexample.CoverFlowView
        xmlns:imageCoverFlow="http://schemas.android.com/apk/lib/com.myexample.CoverFlowView"
        android:id="@+id/coverflow"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        imageCoverFlow:coverflowGravity="center_vertical"
        imageCoverFlow:coverflowLayoutMode="wrap_content"
        imageCoverFlow:enableReflection="true"
        imageCoverFlow:reflectionGap="10dp"
        imageCoverFlow:reflectionHeight="30%"
        imageCoverFlow:reflectionShaderEnable="true"
        imageCoverFlow:visibleImage="5" >
    </com.myexample.CoverFlowView>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textCartDetails"
        android:onClick="onClick"
        android:clickable="true"
        android:text="" />
    </LinearLayout>

错误日志:以下是我每次构建时弹出的错误

    02-23 00:54:53.809: E/AndroidRuntime(2458): FATAL EXCEPTION: main
    02-23 00:54:53.809: E/AndroidRuntime(2458): Process: com.myexample, PID: 2458
    02-23 00:54:53.809: E/AndroidRuntime(2458): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myexample/com.myexample.CreativeProducts}: android.view.InflateException: Binary XML file line #9: Error inflating class com.myexample.CoverFlowView
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at android.os.Handler.dispatchMessage(Handler.java:102)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at android.os.Looper.loop(Looper.java:136)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at android.app.ActivityThread.main(ActivityThread.java:5017)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at java.lang.reflect.Method.invokeNative(Native Method)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at java.lang.reflect.Method.invoke(Method.java:515)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at dalvik.system.NativeStart.main(Native Method)
    02-23 00:54:53.809: E/AndroidRuntime(2458): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class com.myexample.CoverFlowView
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at android.view.LayoutInflater.createView(LayoutInflater.java:620)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at android.app.Activity.setContentView(Activity.java:1929)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at com.myexample.CreativeProducts.onCreate(CreativeProducts.java:44)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at android.app.Activity.performCreate(Activity.java:5231)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     ... 11 more
    02-23 00:54:53.809: E/AndroidRuntime(2458): Caused by: java.lang.reflect.InvocationTargetException
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at java.lang.reflect.Constructor.constructNative(Native Method)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at android.view.LayoutInflater.createView(LayoutInflater.java:594)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     ... 22 more
    02-23 00:54:53.809: E/AndroidRuntime(2458): Caused by: java.lang.IllegalArgumentException: visible image must be an odd number
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at com.myexample.CoverFlowView.initAttributes(CoverFlowView.java:178)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     at com.myexample.CoverFlowView.<init>(CoverFlowView.java:161)
    02-23 00:54:53.809: E/AndroidRuntime(2458):     ... 25 more
    02-23 00:55:00.719: D/dalvikvm(2458): GC_FOR_ALLOC freed 605K, 16% free 3555K/4228K, paused 49ms, total 49ms

1 个答案:

答案 0 :(得分:1)

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:imageCoverFlow="http://schemas.android.com/apk/lib/com.myexample.CoverFlowView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="16dp"
        android:paddingRight="16dp" >

    <com.myexample.CoverFlowView
        android:id="@+id/coverflow"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        imageCoverFlow:coverflowGravity="center_vertical"
        imageCoverFlow:coverflowLayoutMode="wrap_content"
        imageCoverFlow:enableReflection="true"
        imageCoverFlow:reflectionGap="10dp"
        imageCoverFlow:reflectionHeight="30%"
        imageCoverFlow:reflectionShaderEnable="true"
        imageCoverFlow:visibleImage="5" >
    </com.myexample.CoverFlowView>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textCartDetails"
        android:onClick="onClick"
        android:clickable="true"
        android:text="" />
    </LinearLayout>

名称空间必须仅在父布局中提及,然后您应该注册android manifest包名称,这意味着您在版本名称上方提到了androidManifest.xml。