Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Animated vector drawable throws null pointer exception

Hello I am experimenting with animated vector drawables. I want to draw over certain paths, using three states. But when I launch the application, the drawable crashes the app. I have tried to exchange it and it works fine. Here is my code:

    package com.alexjlockwood.example.delight;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class PinActivity  extends AppCompatActivity {

    private static final int[] PIN_STATES = {
            R.attr.state_zeroo,
            R.attr.state_one,
            R.attr.state_two,
            R.attr.state_three,
    };

    @BindView(R.id.countdownIcon2)
    ImageView countdownView;
    int state = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pin);
        ButterKnife.bind(this);
    }

    @OnClick(R.id.rootview)
    void onClick() {

        final int numStates = PIN_STATES.length;
        final int[] stateSet = new int[numStates];
        for (int i = 0; i < stateSet.length; i++) {
            if (i == state) {
                stateSet[i] = PIN_STATES[i];
            } else {
                stateSet[i] = -PIN_STATES[i];
            }
        }
        countdownView.setImageState(stateSet, true);
        state++;
    }
}

Here is my layout

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/rootview"
    android:background="@color/cyan_300"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/countdownIcon2"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_centerInParent="true"
        android:contentDescription="@null"
        android:scaleType="fitCenter"
        app:srcCompat="@drawable/asl_pin" />

</RelativeLayout>

and here is asl for that drawable:

<?xml version="1.0" encoding="utf-8"?>

<item
    android:id="@+id/first"
    android:drawable="@drawable/vd_pin_zero"
    app:state_zeroo="true"/>

<item
    android:id="@+id/second"
    android:drawable="@drawable/vd_pin_begin"
    app:state_begin="true"/>

<item
    android:id="@+id/third"
    android:drawable="@drawable/vd_pin_middle"
    app:state_middle="true"/>

<item
    android:id="@+id/fourth"
    android:drawable="@drawable/vd_pin_end"
    app:state_end="true"/>

<transition
    android:drawable="@drawable/avd_pin_1_to_2"
    android:fromId="@id/first"
    android:toId="@id/second"/>

<transition
    android:drawable="@drawable/avd_pin_2_to_3"
    android:fromId="@id/second"
    android:toId="@id/third"/>


<transition
    android:drawable="@drawable/avd_pin_3_to_4"
    android:fromId="@id/third"
    android:toId="@id/fourth"/>

Here are my transitions:

<animated-vector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt">
<aapt:attr name="android:drawable">
    <vector
        android:name="vector"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24"
        android:viewportHeight="24">
        <path
            android:name="path_outer"
            android:pathData="M 6.025 16.311 C 6.748 16.988 7.511 17.713 8.281 18.496 L 8.281 18.5 C 8.282 18.499 8.282 18.499 8.283 18.498 C 8.283 18.499 8.284 18.499 8.285 18.5 L 8.285 18.496 C 11.138 15.598 13.869 13.494 14.957 11.702 C 18.104 6.511 14.144 0.503 8.285 0.5 L 8.285 0.5 C 8.284 0.5 8.283 0.5 8.283 0.5 C 8.282 0.5 8.282 0.5 8.281 0.5 L 8.281 0.5 C 2.423 0.503 -1.537 6.511 1.61 11.701 C 2.144 12.581 3.075 13.537 4.222 14.625"
            android:fillColor="#00000000"
            android:fillAlpha="0"
            android:strokeColor="#f0f0f0"
            android:strokeWidth="1"
            android:strokeLineCap="round"
            android:strokeLineJoin="round"
            android:fillType="evenOdd"/>
        <path
            android:name="path_middle"
            android:pathData="M 12.301 6.847 C 12.433 7.256 12.503 7.69 12.503 8.143 C 12.503 10.472 10.615 12.363 8.285 12.363 C 5.955 12.363 4.066 10.472 4.066 8.143 C 4.066 5.813 5.955 3.923 8.285 3.923 C 9.568 3.923 10.718 4.497 11.492 5.401"
            android:fillColor="#00000000"
            android:strokeColor="#f0f0f0"
            android:strokeWidth="1"
            android:strokeLineCap="round"
            android:strokeLineJoin="round"/>
        <path
            android:name="path_inner"
            android:pathData="M 9.833 8.143 C 9.833 8.415 9.761 8.682 9.625 8.917 C 9.49 9.153 9.294 9.349 9.059 9.484 C 8.823 9.62 8.556 9.692 8.284 9.692 C 8.012 9.692 7.745 9.62 7.51 9.484 C 7.274 9.349 7.078 9.153 6.943 8.917 C 6.807 8.682 6.735 8.415 6.735 8.143 C 6.735 7.732 6.898 7.338 7.189 7.048 C 7.479 6.757 7.873 6.594 8.284 6.594 C 8.695 6.594 9.089 6.757 9.379 7.048 C 9.67 7.338 9.833 7.732 9.833 8.143 Z"
            android:fillColor="#00000000"
            android:strokeColor="#f0f0f0"
            android:strokeWidth="1"/>
        <group android:name="group"/>
        <path
            android:name="animation_1"
            android:pathData="M 6.025 16.311 C 6.748 16.988 7.511 17.713 8.281 18.496 L 8.281 18.5 C 8.282 18.499 8.282 18.499 8.283 18.498 C 8.283 18.499 8.284 18.499 8.285 18.5 L 8.285 18.496 C 11.138 15.598 13.869 13.494 14.957 11.702 C 18.104 6.511 14.144 0.503 8.285 0.5 L 8.285 0.5 C 8.284 0.5 8.283 0.5 8.283 0.5 C 8.282 0.5 8.282 0.5 8.281 0.5 L 8.281 0.5 C 2.423 0.503 -1.537 6.511 1.61 11.701 C 2.144 12.581 3.075 13.537 4.222 14.625"
            android:fillColor="#00000000"
            android:strokeColor="#ffffff"
            android:strokeWidth="1"
            android:strokeLineCap="round"
            android:strokeLineJoin="round"/>
    </vector>
</aapt:attr>
<target android:name="animation_1">
    <aapt:attr name="android:animation">
        <objectAnimator
            android:propertyName="trimPathEnd"
            android:duration="1000"
            android:valueFrom="0"
            android:valueTo="1"
            android:valueType="floatType"
            android:interpolator="@android:interpolator/fast_out_slow_in"/>
    </aapt:attr>
</target>

the rest of them look the same, just have different colours.

I have no idea why this is crashing. I've been doing the same as the code in here

Comments