**I'm trying to implement a TextSwitcher in a recyclerView but every time I debug it return an error message : java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewGroup$LayoutParams android.view.View.getLayoutParams()' on a null object reference
Here is my Code XML
<TextSwitcher
android:id="@+id/textSwitcher_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textAlignment="textStart"
android:lineSpacingExtra="5dp"
android:textColor="@color/white"
android:textSize="@dimen/appbar_padding"
android:layout_gravity="start"
android:text=""/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textAlignment="textStart"
android:lineSpacingExtra="5dp"
android:textColor="@color/white"
android:textSize="@dimen/appbar_padding"
android:layout_gravity="start"
/>
</TextSwitcher>
Here is my Java Code :onBindViewHolder from RecyclerView Adapter
@Override
protected void onBindViewHolder(@NonNull ViewHolderCard holder, int position, @NonNull ModelBet model) {
TextSwitcher textSwitcher=holder.getTextSwitcher();
//textSwitcher.setText(TEXT[mPosition]);
textSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
TextView textView=new TextView(context);
textView.setTextColor(context.getResources().getColor(R.color.white));
textView.setTextSize(16);
return null;
}
});
}
Here my ViewHolder
public class ViewHolderCard extends RecyclerView.ViewHolder {
...
public TextSwitcher textSwitcher;
public ViewHolderCard(@NonNull View itemView) {
super(itemView);
view=itemView;
...
textSwitcher=(TextSwitcher)view.findViewById(R.id.textSwitcher_card);
}
@NonNull
public TextSwitcher getTextSwitcher() {
return textSwitcher;
}
While i have initialized my TextSwitcher. I don't really know where the problem comes from