【问题标题】:Android Stackoverflow Errror: ViewGroup.jumpDrawablesToCurrentStateAndroid Stackoverflow 错误:ViewGroup.jumpDrawablesToCurrentState
【发布时间】:2018-05-05 11:06:21
【问题描述】:

我有问题。我收到了 Stackoverflow 错误。我尝试减少布局等。但没有任何效果。

我有一个视图寻呼机,在片段中是 recyclerviews 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)

有人可以帮帮我吗?

【问题讨论】:

    标签: android android-fragments android-recyclerview android-viewpager stack-overflow


    【解决方案1】:

    问题解决了。

    我不知道错误在哪里,但可能是一个空列表或 ImageAssets,我用矢量资产替换并激活 Gradle 中的库。

    对于在视图页面中遇到相同问题的人:停用所有片段并启用它们,以测试错误在哪里。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-26
      • 1970-01-01
      • 1970-01-01
      • 2015-04-06
      • 1970-01-01
      相关资源
      最近更新 更多