Search code examples
androidandroid-fragmentsandroid-recyclerviewandroid-viewpagerstack-overflow

Android Stackoverflow Errror: ViewGroup.jumpDrawablesToCurrentState


I have a problem. I got an Stackoverflow Error. I tried reduced the Layout and so on. But nothing worked.

I have a view pager and in the fragments are recyclerviews 4 times. (one in each). The inflater Code

View root = inflater.inflate(R.layout.content_main, container, false);

One Layout in Fragment for example:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
    android:id="@+id/list_view"
    xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_margin="10dp"
    android:layout_marginTop="15dp"
    android:layout_height="wrap_content" />

And this is the Layout for the ReclerView Item

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    android:id="@+id/cv"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_margin="20dp"
    android:clickable="true"
    android:background="?attr/selectableItemBackground"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:gravity="center|left"
        android:padding="10dp"
        android:clickable="true"
        android:background="?attr/selectableItemBackground"
        >

        <ImageView
            android:id="@+id/album_cover"
            android:layout_width="33dp"
            android:layout_height="50dp"
            android:layout_marginRight="16dp"
            android:src="@drawable/ic_supervisor_account_black_24dp" />

        <TextView
            android:id="@+id/album_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Artistname"
            android:textColor="#000000"
            android:textSize="15sp" />


    </LinearLayout>

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

One Layout has a Relative Layout but it works before I made some changes:

 <android.support.v7.widget.CardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/cv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:background="?attr/selectableItemBackground"
        android:layout_margin="10dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="16dp"
            android:clickable="true"
            android:longClickable="true"
            android:background="?attr/selectableItemBackground"
            >

            <ImageView
                android:id="@+id/album_cover"
                android:layout_width="66dp"
                android:layout_height="50dp"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:layout_marginRight="16dp"
                android:src="@drawable/spring_276014_640" />

            <TextView
                android:id="@+id/album_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@+id/album_cover"
                android:text="Albumtitel"
                android:textColor="#000000"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/album_artist"
                android:layout_width="wrap_content"
                android:layout_marginTop="5dp"
                android:layout_height="wrap_content"
                android:layout_below="@+id/album_name"
                android:layout_toRightOf="@+id/album_cover"
                android:text="von Artist xy" />

        </RelativeLayout>

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

Captureing View Table is not possible because app is going down before it changes the layout.

Bitmaps are scaled.

Here is my Adapter:

public class DefaultAdapter extends RecyclerView.Adapter<DefaultAdapter.SongViewHolder> {
private Context con;
private List<String> names;
boolean useplaylist;

// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder
public static class SongViewHolder extends RecyclerView.ViewHolder {
    CardView cv;
    TextView title;

    SongViewHolder(View itemView) {
        super(itemView);
        cv = (CardView)itemView.findViewById(R.id.cv);
        title = (TextView)itemView.findViewById(R.id.album_name);
    }
}

// Provide a suitable constructor (depends on the kind of dataset)
public DefaultAdapter(Context context,List<String> names,boolean playlist) {
    con = context;
    this.names = names;
    useplaylist = playlist;
}

// Create new views (invoked by the layout manager)
@Override
public SongViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
    View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.playlist_item, viewGroup, false);



    SongViewHolder pvh = new SongViewHolder(v);
    return pvh;
}

@Override
public void onBindViewHolder(SongViewHolder personViewHolder, int i) {
    personViewHolder.title.setText(names.get(i));
}

// Return the size of your dataset (invoked by the layout manager)
@Override
public int getItemCount() {
    return names.size();
}

@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
}
}

Log:

java.lang.StackOverflowError: stack size 8MB\n
    at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:6108)
    at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:6112)
    at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:6112)
    at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:6112)
    at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:6112)
    at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:6112)

Can somebody help me?


Solution

  • Problem solved.

    I don't know where the Error was but maby it was an empty list or the ImageAssets wich I replaced with vector assets and activate the Libary in the Gradle.

    For thoos who have the same problem in a viewpage: Deactivate all fragments and enable them single, to test where the error is.