为什么我在使用moondroid coverflow时会出现NullPointerException?

时间:2016-11-08 17:42:56

标签: android coverflow

我是android开发的初学者,我使用moondroid CoverFlow(外部库)来创建CoverFlow,但是我不知道为什么在XML中使用它时会得到一个空指针异常。

这是我的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)

1 个答案:

答案 0 :(得分: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

即可