rosenpin / fading-text-view

A TextView that changes its content automatically every few seconds
1.74k stars 222 forks source link

Clicking Apply Changes in Android Studio causes crash when Activity containing FadingTextView is in foreground #20

Open rockakassh opened 2 years ago

rockakassh commented 2 years ago

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> <androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent" android:id="@+id/drawerid" android:background="@color/background" tools:context=".MainActivity">

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
    <androidx.coordinatorlayout.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">  

    <!-- Main content -->

 <FrameLayout
    android:id="@+id/framelayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/action_bar"
    android:layout_marginTop="60dp"
    android:layout_marginBottom="48dp"
    >

</FrameLayout>
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom">

    <include layout="@layout/bottom_navigation"
        android:id="@+id/bottom_view"
        android:layout_height="wrap_content"
        android:layout_width="match_parent" />

</FrameLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>
<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_toStartOf="@id/d_layout"
    android:layout_alignParentStart="true"
    android:layout_alignBottom="@id/d_layout"
    android:layout_marginBottom="5dp"
    >

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/constraintLayout2"
        android:layout_width="0dp"
        android:layout_height="40dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <ProgressBar
            android:id="@+id/progress_bar"
            style="@style/Widget.AppCompat.ProgressBar.Horizontal"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginHorizontal="10sp"
            android:indeterminateDrawable="@drawable/bg_progress_bar_green"
            android:max="100"
            android:progress="1"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@id/clicks"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/step1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="5dp"
            android:layout_marginVertical="5dp"
            android:background="@drawable/radius_button_bg"
            android:gravity="center"
            android:text="1"
            android:textColor="@color/whiteTextColor"
            app:layout_constraintBottom_toBottomOf="@id/progress_bar"
            app:layout_constraintStart_toStartOf="@id/progress_bar"

            app:layout_constraintTop_toTopOf="@id/progress_bar" />

        <TextView
            android:id="@+id/step2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:layout_marginVertical="5dp"
            android:background="@drawable/radius_button_bg"

            android:gravity="center"
            android:text="25"

            android:textColor="@color/whiteTextColor"
            app:layout_constraintBottom_toBottomOf="@id/progress_bar"
            app:layout_constraintStart_toEndOf="@id/step1"
            app:layout_constraintEnd_toStartOf="@id/step3"
            app:layout_constraintTop_toTopOf="@id/progress_bar" />

        <TextView
            android:id="@+id/step3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:layout_marginVertical="5dp"
            android:background="@drawable/radius_button_bg"

            android:gravity="center"
            android:text="50"
            app:layout_constraintEnd_toStartOf="@id/step4"
            android:textColor="@color/whiteTextColor"
            app:layout_constraintBottom_toBottomOf="@id/progress_bar"
            app:layout_constraintStart_toEndOf="@id/step2"
            app:layout_constraintTop_toTopOf="@id/progress_bar" />

        <TextView
            android:id="@+id/step4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:layout_marginVertical="5dp"
            android:background="@drawable/radius_button_bg"

            android:gravity="center"
            android:text="100"
            app:layout_constraintEnd_toEndOf="@id/progress_bar"
            android:textColor="@color/whiteTextColor"
            app:layout_constraintBottom_toBottomOf="@id/progress_bar"

            app:layout_constraintTop_toTopOf="@id/progress_bar" />
        <com.tomer.fadingtextview.FadingTextView
            app:timeout="2000"
            android:layout_width="65dp"
            android:layout_height="wrap_content"
            android:id="@+id/clicks"
            android:text="@array/hello"
            android:gravity="center"

            app:layout_constraintBottom_toBottomOf="@id/progress_bar"
            app:layout_constraintStart_toEndOf="@id/progress_bar"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="@id/progress_bar"
            android:textStyle="bold"
            android:textColor="#311B92"
            android:textSize="16sp"/>
    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentTop="true"

    android:id="@+id/d_layout"
    android:elevation="5dp"
    android:orientation="horizontal">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="wrap_content"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="15dp"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="40dp"
        android:layout_height="wrap_content"
        android:background="@drawable/coin_outline_view_bg"

        android:elevation="15dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:orientation="horizontal"
            android:paddingBottom="3dp"
            android:paddingEnd="17dp"
            android:paddingStart="5dp"
            android:paddingTop="3dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="3dp"
                android:text="💰"
                android:textColor="@color/colorAccent"

                android:textSize="18sp"

                android:textStyle="bold"

                />

            <ProgressBar
                android:id="@+id/process_bar"
                android:layout_width="40dp"
                android:layout_height="24dp"
                android:layout_gravity="center_vertical" />

            <TextView
                android:id="@+id/coin_count"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:text="0"
                android:textColor="@color/darkTextColor"
                android:textSize="18sp"
                android:textStyle="bold"

                android:visibility="gone"

                />
        </LinearLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="43dp"
        android:layout_height="43dp"

        android:layout_marginBottom="15dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/bg_fab"
        android:elevation="15dp"
        android:layout_marginEnd="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"

        app:layout_constraintTop_toTopOf="parent">

        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/drawer_icon"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="3dp"

            android:clickable="true"
            android:focusable="true"
            android:src="@drawable/person"

            app:civ_border_color="@color/colorAccent"
            app:civ_border_width="1dp"
            app:civ_circle_background_color="@color/whiteTextColor" />

    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/coinButton"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_marginEnd="20dp"
    android:layout_marginBottom="65dp"
    android:clickable="true"
    android:theme="@style/MyMaterialTheme"
    app:fabCustomSize="50dp"
    android:layout_alignParentEnd="true"
    android:layout_alignParentBottom="true"
    android:scaleType="center"
    android:visibility="gone"

    app:tint="@null"
    app:srcCompat="@drawable/coin_white"
    android:backgroundTint="@color/gradientLightBlue"
    android:focusable="true"
    android:contentDescription="Survey Offer" />

</RelativeLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone"
        android:id="@+id/view"
        android:orientation="vertical" />
</RelativeLayout>
<com.rom4ek.arcnavigationview.ArcNavigationView

    android:id="@+id/nav_view_right"

    android:layoutDirection="ltr"

    android:layout_width="wrap_content"

    android:layout_height="match_parent"

    android:layout_gravity="end"

    android:background="@android:color/white"

    android:fitsSystemWindows="true"

    app:arc_cropDirection="cropOutside"

    app:arc_width="52dp"

    app:itemBackground="@android:color/white"

    app:menu="@menu/main_activity_actions"/>

</androidx.drawerlayout.widget.DrawerLayout>

loagcat

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.curiousminds.ytcreatorszone/com.curiousminds.ytcreatorszone.MainActivity}: android.view.InflateException: Binary XML file line #2 in com.curiousminds.ytcreatorszone:layout/activity_main: Attempt to read from null array at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3704) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3871) at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5809) at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5712) at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:100) at android.app.ClientTransactionHandler.executeTransaction(ClientTransactionHandler.java:58) at android.app.ActivityThread.handleRelaunchActivityLocally(ActivityThread.java:5765) at android.app.ActivityThread.access$3400(ActivityThread.java:292) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2318) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:257) at android.app.ActivityThread.main(ActivityThread.java:8239) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1006) Caused by: android.view.InflateException: Binary XML file line #2 in com.curiousminds.ytcreatorszone:layout/activity_main: Attempt to read from null array Caused by: java.lang.NullPointerException: Attempt to read from null array at com.tomer.fadingtextview.FadingTextView.startAnimation(FadingTextView.java:289) at com.tomer.fadingtextview.FadingTextView.resume(FadingTextView.java:62) at com.tomer.fadingtextview.FadingTextView.onAttachedToWindow(FadingTextView.java:104) at android.view.View.dispatchAttachedToWindow(View.java:20731) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3516) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3516) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3516) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3516) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3516) at android.view.ViewGroup.addViewInner(ViewGroup.java:5359) at android.view.ViewGroup.addView(ViewGroup.java:5137) at android.view.ViewGroup.addView(ViewGroup.java:5109) at android.view.LayoutInflater.inflate(LayoutInflater.java:689) at android.view.LayoutInflater.inflate(LayoutInflater.java:532) at android.view.LayoutInflater.inflate(LayoutInflater.java:479) at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:699) at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195) at com.curiousminds.ytcreatorszone.MainActivity.onCreate(MainActivity.java:131) at android.app.Activity.performCreate(Activity.java:8146) at android.app.Activity.performCreate(Activity.java:8130) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1310) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3673) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3871) at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5809) at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5712) at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:100) 2021-11-19 16:20:11.849 30665-30665/com.curiousminds.ytcreatorszone E/AndroidRuntime: at android.app.ClientTransactionHandler.executeTransaction(ClientTransactionHandler.java:58) at android.app.ActivityThread.handleRelaunchActivityLocally(ActivityThread.java:5765) at android.app.ActivityThread.access$3400(ActivityThread.java:292) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2318) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:257) at android.app.ActivityThread.main(ActivityThread.java:8239) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1006)

ebayraktar commented 10 months ago

Error says:

Caused by: java.lang.NullPointerException: Attempt to read from null array at com.tomer.fadingtextview.FadingTextView.startAnimation(FadingTextView.java:289)

This error is relative to the older version of the library which was the message pointed FadingTextView.java:289.

This might be starting animation before checking the length of the texts.

version 3.1 fixes the error in FadingTextView.kt:218 (#22)

@rockakassh Can you check that the latest version fixes the problem?