2016-11-08 54 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

相关问题