team-supercharge / ShimmerLayout

DEPRECATED - Memory efficient shimmering effect for Android applications by Supercharge.
Apache License 2.0
2.52k stars 284 forks source link

Im using shimmer On a CardView which is attached to a adapter and the app the crarshes? #79

Closed chigup closed 5 years ago

chigup commented 5 years ago

Here is my layout

` <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" android:orientation="vertical" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.026">

    <io.supercharge.shimmerlayout.ShimmerLayout
        android:id="@+id/shimmer_Main_card"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="50dp"
        android:paddingLeft="30dp"
        android:paddingRight="30dp"
        app:shimmer_animation_duration="1200">

    <android.support.v7.widget.CardView
        android:id="@+id/hostelCard"
        android:elevation="10dp"
        app:cardCornerRadius="30dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="10dp">

        <RelativeLayout
            android:layout_width="330dp"
            android:layout_height="220dp"
            android:layout_gravity="center">

            <ImageView
                android:id="@+id/LocationMainImage"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:layout_alignParentEnd="true"
                android:layout_marginStart="0dp"
                android:layout_marginTop="7dp"
                android:layout_marginEnd="10dp"
                android:padding="4dp"
                android:src="@drawable/logo" />

            <TextView
                android:id="@+id/LocationName"
                android:layout_width="wrap_content"
                android:layout_height="38dp"
                android:layout_below="@id/LocationMainImage"
                android:layout_alignParentStart="true"
                android:layout_marginStart="3dp"
                android:layout_marginTop="-217dp"
                android:background="@color/black"
                android:text="Hostel 1"
                android:textAllCaps="true"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Title"
                android:textColor="@color/yellow" />

        </RelativeLayout>

    </android.support.v7.widget.CardView>

    </io.supercharge.shimmerlayout.ShimmerLayout>

</LinearLayout>

Thanks in advance`

GuanacoDevs commented 5 years ago

What does your logcat says? Can you share your adapter?

chigup commented 5 years ago

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.teepe.teepe, PID: 9014 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.teepe.teepe/com.teepe.teepe.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void io.supercharge.shimmerlayout.ShimmerLayout.startShimmerAnimation()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void io.supercharge.shimmerlayout.ShimmerLayout.startShimmerAnimation()' on a null object reference at com.teepe.teepe.MainActivity.onCreate(MainActivity.java:97) at android.app.Activity.performCreate(Activity.java:6662)

veghtomi commented 5 years ago

@chigup It seems very very strange that you got an NPE on the layout at an adapter.

Could you create a sample app where you can reproduce the crash? It would be a great help.

GuanacoDevs commented 5 years ago

Seems like you haven't initialized the ShimmerLayout. Maybe you are calling startShimmerAnimation() before findViewById(R.id.shimmer_Main_card) or you are not initializing it appropiately in your ViewHolder

chigup commented 5 years ago

Thanks @GuanacoDevs this was the problem