Ошибка Stackoverflow Android: ViewGroup.jumpDrawablesToCurrentState - PullRequest
0 голосов
/ 05 мая 2018

У меня проблема. Я получил ошибку Stackoverflow. Я пытался уменьшить макет и так далее. Но ничего не сработало.

У меня есть видовой пейджер, а во фрагментах 4 раза. (по одному в каждом). Код инфлятора

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

Один макет во фрагменте, например:

<?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" />

И это макет для элемента ReclerView

<?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>

Один макет имеет относительный макет, но он работает до того, как я внес некоторые изменения:

 <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>

Захват таблицы просмотра невозможен, поскольку приложение закрывается, прежде чем оно изменит макет.

Растровые изображения масштабируются.

Вот мой адаптер:

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);
}
}

Вход:

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)

Может кто-нибудь мне помочь?

1 Ответ

0 голосов
/ 12 мая 2018

Проблема решена.

Я не знаю, где была Ошибка, но, возможно, это был пустой список или ImageAssets, которые я заменил на векторные активы и активировал Libary в Gradle.

Для тех, у кого такая же проблема на странице просмотра: деактивируйте все фрагменты и включите их по одному, чтобы проверить, где ошибка.

...