Android Studio:W / OpenGLRenderer:无法选择配置为EGL_SWAP_BEHAVIOR_PRESERVED

时间:2018-02-19 00:57:34

标签: java xml android-studio

我正在尝试制作电影列表,但它只显示带有应用名称的白色屏幕。显然,我有一个非常类似的程序,它运行得非常好。这是我运行程序时得到的结果。

  

W / OpenGLRenderer:无法选择带有EGL_SWAP_BEHAVIOR_PRESERVED的配置,重试没有...

我发现有人说如果xml代码中有错误会发生此错误,但我仍然会提供我的java代码。

public class MainActivity extends AppCompatActivity {

private ListView mListView;
private Context mContext;
ArrayList<Movie> movieList;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mContext = this;
    final ArrayList<Movie> movieList = Movie.getMoviesFromFile("movies.json", this);
    MovieAdapter adapter = new MovieAdapter(this, movieList);

    mListView = findViewById(R.id.movie_list_view);
    mListView.setAdapter(adapter);

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Movie selectedMovie = movieList.get(i);

            Intent detailIntent = new Intent(mContext, MovieDetailActivity.class);
            detailIntent.putExtra("title", selectedMovie.title);
            detailIntent.putExtra("description", selectedMovie.description);
            detailIntent.putExtra("poster", selectedMovie.poster);

            startActivity(detailIntent);
        }
    });
}

以下是我的适配器。

public class MovieAdapter extends BaseAdapter{
private Context mContext;
private ArrayList<Movie> mMovieList;
private LayoutInflater mInflater;

public MovieAdapter(Context mContext, ArrayList<Movie> mMovieList){
    this.mContext = mContext;
    this.mMovieList = mMovieList;
    mInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public int getCount(){return mMovieList.size();}
@Override
public Object getItem(int pos){return mMovieList.get(pos);}
@Override
public long getItemId(int pos){return pos;}
@Override
public View getView(int pos, View convertView, ViewGroup parent){
    ViewHolder holder;

    if(convertView == null){
        convertView = mInflater.inflate(R.layout.list_item_movie, parent, false);
        holder = new ViewHolder();
        holder.titleTextView = convertView.findViewById(R.id.title);
        holder.charactersTextView = convertView.findViewById(R.id.main_characters);
        holder.descriptionTextView = convertView.findViewById(R.id.description);
        holder.thumbnailImageView = convertView.findViewById(R.id.poster);

        convertView.setTag(holder);
    } else{
        holder = (ViewHolder)convertView.getTag();
    }

    TextView titleTextView = holder.titleTextView;
    TextView descriptionTextView = holder.descriptionTextView;
    TextView charactersTextView = holder.charactersTextView;
    ImageView thumbnailImageView = holder.thumbnailImageView;
    Movie movie = (Movie)getItem(pos);

    titleTextView.setText(movie.title);
    titleTextView.setTextSize(20);

    charactersTextView.setText(movie.main_characters);
    charactersTextView.setTextSize(13);

    descriptionTextView.setText(movie.description);
    descriptionTextView.setTextSize(9);

    Picasso.with(mContext).load(movie.poster).into(thumbnailImageView);
    return convertView;
}

private static class ViewHolder{
    public TextView titleTextView;
    public TextView descriptionTextView;
    public ImageView thumbnailImageView;
    public TextView charactersTextView;
}

}

以下是xml代码。

  

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.user.junepyolee_miniapp1.MainActivity">

<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/movie_list_view" />

  

list_item_movie.xml

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout   xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<ImageView
    android:id="@+id/poster"
    android:layout_width="90dp"
    android:layout_height="140dp"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_marginStart="4dp"
    android:layout_marginTop="6dp"
    android:layout_marginBottom="6dp"
    android:layout_centerVertical="true"
    android:scaleType="fitCenter"
    android:contentDescription="This is a thumbnail"
    app:srcCompat="@mipmap/ic_launcher" />

<RelativeLayout
    android:id="@+id/movie_list_text_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/poster"
    android:layout_alignParentTop="false"
    android:layout_toRightOf="@+id/poster">

    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="3dp"
        android:text="Title"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/description"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/title"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="3dp"
        android:maxLines="3"
        android:text="description"
        android:textSize="9sp" />

    <TextView
        android:id="@+id/main_characters"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignEnd="@+id/description"
        android:layout_below="@+id/description"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="3dp"
        android:text="characters max 3 people"
        android:textSize="13sp" />

    <TextView
        android:id="@+id/hasSeen"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/main_characters"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="3dp"
        android:text="has seen?"
        android:textSize="11sp" />

</RelativeLayout>

有没有人有这方面的解决方案?

2 个答案:

答案 0 :(得分:0)

这仅是警告,并且由于重试时没有配置选项而没有(我从您的评论中假定)跟进错误,因此这不是问题的根源。

这不是一个不好的猜测,因为这是与OpenGL相关的类(android / opengl / EGL14),但这不是问题的根源。

您可以在https://www.khronos.org/egl上阅读有关EGL的更多信息。

答案 1 :(得分:0)

可能不是您的解决方案的答案,但我遇到了同样的问题,它对我不起作用的原因是我的列表是空的。检查列表的大小并确保其不为零。