如何使用类<unknown>解决android.view.InflateException?

时间:2016-09-12 20:23:58

标签: android youtube-api android-recyclerview recycler-adapter

我正在使用带有recyclerview适应器的YouTubeBaseActivity。:

android.view.InflateException: Binary XML file line #19: Binary XML file line #19: Error inflating class <unknown>
   at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:423)

代码

public class YoutubeVideoPlayerActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {

        private static final int RECOVERY_REQUEST = 1;
        private YouTubePlayerView youTubeView;
        String uri;
        String title;
        TextView videotitle;
        RecyclerView recyclerView;
        RequestQueue requestQueue;
        YoutubevideoplayersreenAdapter adapder;
        List<VideoThumblineData> videoThumblineDatas = new ArrayList<VideoThumblineData>();
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            Intent intent = getIntent();
            uri = intent.getStringExtra("uri");
            title = intent.getStringExtra("title");
            youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
            videotitle = (TextView)findViewById(R.id.videotitle);
            videotitle.setText(title);
            youTubeView.initialize(Config.YOUTUBE_API_KEY, this);
            recyclerView =(RecyclerView)findViewById(R.id.player_list_recycler_view);
            recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
            requestQueue = Volley.newRequestQueue(getApplicationContext());

            requestQueue.add(new JsonArrayRequest(JSON_STRING[Position], new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    try {
                        for (int i=response.length()-1; i>= 0 ;i--){
                            JSONObject data = (JSONObject) response.get(i);
                            Log.d("video :"," :"+response);
                            String ids = data.getString("Id");
                            String video_headings = data.getString("video_Heading");
                            String video_ids = data.getString("video_Id");
                            String video_duration = data.getString("duration");
                            videoThumblineDatas.add(new VideoThumblineData(ids,video_headings,video_ids,video_duration));
                        }
                        adapder =new YoutubevideoplayersreenAdapter(videoThumblineDatas);
                        recyclerView.setAdapter(adapder);
                        adapder.notifyDataSetChanged();
                    }catch (JSONException e){
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            }));
        }
    }


public class YoutubevideoplayersreenAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List<VideoThumblineData> albumList;

    class RelatedThumbnailHolder extends RecyclerView.ViewHolder {

        public TextView title,duration;
        public YouTubeThumbnailView thumbnail;


        public RelatedThumbnailHolder(View view) {
            super(view);
            title = (TextView) view.findViewById(R.id.player_title);
            thumbnail = (YouTubeThumbnailView) view.findViewById(R.id.player_thumbnail);
            duration = (TextView)view.findViewById(R.id.player_duration);
        }


    }
    public YoutubevideoplayersreenAdapter(List<VideoThumblineData> albumList) {
        this.albumList = albumList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.youtubeplayer_listview, parent,false);
        return new RelatedThumbnailHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        RelatedThumbnailHolder relatedthumbnailHolder = (RelatedThumbnailHolder)holder;
        relatedthumbnailHolder.title.setText(albumList.get(position).getVideo_heading());
        relatedthumbnailHolder.duration.setText(albumList.get(position).getDuration());
        relatedthumbnailHolder.thumbnail.initialize(Config.YOUTUBE_API_KEY, new YouTubeThumbnailView.OnInitializedListener() {
            @Override
            public void onInitializationSuccess(YouTubeThumbnailView youTubeThumbnailView, YouTubeThumbnailLoader youTubeThumbnailLoader) {
                youTubeThumbnailLoader.setVideo(albumList.get(position).getVideo_id());
            }
            @Override
            public void onInitializationFailure(YouTubeThumbnailView youTubeThumbnailView, YouTubeInitializationResult youTubeInitializationResult) {

            }
        });
        relatedthumbnailHolder.thumbnail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent(mContext, YoutubeVideoPlayerActivity.class);
                i.putExtra("uri",albumList.get(position).getVideo_id());
                i.putExtra("title",albumList.get(position).getVideo_heading());
                view.getContext().startActivity(i);
            }
        });
        relatedthumbnailHolder.title.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent(mContext, YoutubeVideoPlayerActivity.class);
                i.putExtra("uri",albumList.get(position).getVideo_id());
                i.putExtra("title",albumList.get(position).getVideo_heading());
                view.getContext().startActivity(i);
            }
        });
    }

    @Override
    public int getItemCount() {
        return albumList.size();
    }
}
使用YoutubeVideoPlayerActivity的

activity_main.xml文件,这是xml文件

错误随附

inflater android.view.InflateException with class <unknown>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".Activity.YoutubeVideoPlayerActivity">

    <com.google.android.youtube.player.YouTubePlayerView
        android:id="@+id/youtube_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:id="@+id/cardview"
        android:background="#ffffff"
        android:layout_height="wrap_content"
        android:layout_below="@+id/youtube_view"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="title"
        android:gravity="center"
        android:id="@+id/videotitle"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    </android.support.v7.widget.CardView>
    <android.support.v7.widget.RecyclerView
        android:id="@+id/player_list_recycler_view"
        android:layout_width="match_parent"
        android:overScrollMode="never"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_height="match_parent"
        android:layout_below="@+id/cardview"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="41dp" />

</RelativeLayout>

0 个答案:

没有答案