2016-11-08 84 views
1

我是一名Android開發的初學者,我使用moondroid CoverFlow(外部庫)創建CoverFlow,但我不明白爲什麼我在XML中使用它時會出現空指針異常。爲什麼在使用moondroid coverflow時會出現NullPointerException?

這裏是我的XML文件:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:coverflow="http://schemas.android.com/tools"> 

    <it.moondroid.coverflow.components.ui.containers.FeatureCoverFlow 
     android:id="@+id/coverflow" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     coverflow:coverHeight="@dimen/cover_height" 
     coverflow:coverWidth="@dimen/cover_width" 
     coverflow:maxScaleFactor="1.5" 
     coverflow:reflectionGap="0px" 
     coverflow:rotationThreshold="0.5" 
     coverflow:scalingThreshold="0.5"> 

    </it.moondroid.coverflow.components.ui.containers.FeatureCoverFlow> 

</RelativeLayout> 

這裏是我得到的錯誤是:

java.lang.NullPointerExceptio at it.moondroid.coverflow.components.ui.containers.FeatureCoverFlow.dispatchDraw(FeatureCoverFlow.java:471) 
at android.view.View.draw(View.java:16974) at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3764) at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61) at android.view.ViewGroup.drawChild(ViewGroup.java:3764) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550) at android.view.View.draw(View.java:16974) at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3764) at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61) at android.view.ViewGroup.drawChild(ViewGroup.java:3764) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550) at android.view.View.draw(View.java:16974) at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3764) at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61) at android.view.ViewGroup.drawChild(ViewGroup.java:3764) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550) at android.view.View.draw(View.java:16974) at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3764) at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61) at android.view.ViewGroup.drawChild(ViewGroup.java:3764) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550) at android.view.View.draw(View.java:17071) 
+0

我們需要更多的stacktace和代碼,以幫助 – Emmanuel

+0

@Emmanuel我提供其餘的堆棧跟蹤 – Abhinav422

回答

0

只要看看它被設置這樣

樣本示例
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:coverflow="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@android:color/darker_gray" 
tools:context="it.moondroid.carousellayoutdemo.CoverFlowActivity"> 


<it.moondroid.coverflow.components.ui.containers.FeatureCoverFlow 
    android:id="@+id/coverflow" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    coverflow:coverHeight="@dimen/cover_height" 
    coverflow:coverWidth="@dimen/cover_width" 
    coverflow:maxScaleFactor="1.5" 
    coverflow:reflectionGap="0px" 
    coverflow:rotationThreshold="0.5" 
    coverflow:scalingThreshold="0.5" 
    coverflow:spacing="0.6" /> 

<TextSwitcher 
    android:id="@+id/title" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingBottom="16dp" 
    android:layout_alignParentBottom="true" 
    android:layout_centerVertical="true" /> 

</RelativeLayout> 

並添加一些額外的文件like this 只要看看sample too

+0

仍然堅持錯誤 – Abhinav422

+0

你得到的紅線在XML?添加你的java代碼 –

+0

確定程序運行,非常感謝 – Abhinav422

相關問題