why am I getting NullPointerException when using m

2019-07-24 20:06发布

I am a beginner in android development, I am using moondroid CoverFlow (external library) to create a CoverFlow, but I don't get why I am getting a null pointer exception when using it in XML.

Here is my XML file:

<?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>

And here is the error that I am getting is:

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条回答
相关推荐>>
2楼-- · 2019-07-24 20:27

Just take a look at the sample example it is set like this

<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>

and add some additional file like this Just take a look at the sample too

查看更多
登录 后发表回答