无法访问其他活动中的进度条

时间:2016-07-28 07:31:17

标签: android android-recyclerview android-videoview

我在视频视图,文本视图等布局中有一些对象,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
android:id="@+id/cardView_mypost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_vertical_margin"
app:cardCornerRadius="@dimen/activity_vertical_margin"
app:cardElevation="@dimen/activity_vertical_margin"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:background="@color/web_withe_color"
   android:animateLayoutChanges="@anim/anim_list"
   android:padding="8dp"
>
<!-- Thumbnail Image -->
<VideoView
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:id="@+id/video_orw"
    />
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="@dimen/worth"
    android:id="@+id/txt_titr_videopost"
    android:background="#ee8888"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="Large Text"
    android:id="@+id/txt_date_videopost"
    android:layout_alignBaseline="@+id/txt_cunter_videopost"
    android:layout_alignBottom="@+id/txt_cunter_videopost"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:text="Small Text"
    android:id="@+id/txt_cunter_videopost"
    android:textColor="@color/bright_foreground_disabled_material_dark"
    android:layout_centerVertical="true"
    android:layout_alignRight="@+id/txt_date_videopost"
    android:layout_alignEnd="@+id/txt_date_videopost" />
<MediaController
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/mediaController2"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:visibility="gone" />
<ProgressBar
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/progressBar_load_video"
    android:layout_centerVertical="true"
    android:layout_alignRight="@+id/txt_titr_videopost"
    android:layout_alignEnd="@+id/txt_titr_videopost" />
</RelativeLayout>

这是recyclerview中的一组行, 和我的代码

 public StudentViewHolder(View v) {
        super(v);

        progress_video=new ProgressBar(context);
        final ProgressDialog[] pDialog = new ProgressDialog[1];
        final ShowMessage sm=new ShowMessage(context);

        thumbNail = (VideoView) itemView
              .findViewById(R.id.video_orw);
        titr = (TextView) itemView.findViewById(R.id.txt_titr_videopost);
        year = (TextView) itemView.findViewById(R.id.txt_date_videopost);
        fi = (TextView) itemView.findViewById(R.id.txt_cunter_videopost);
        progressBar=(ProgressBar) itemView.findViewById(R.id.progressBar1);
        progress_video=(ProgressBar) v.findViewById(R.id.progressbar_video);

        v.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {


                sm.show();


                if(VideoGalery.mediacontrol==null)
                VideoGalery.mediacontrol=new MediaController(context);


                VideoGalery.mediacontrol.setAnchorView(VideoGalery.videoview);

                VideoGalery.videoview.setMediaController(VideoGalery.mediacontrol);
             int itemPosition = DataAdapterPostVideo.recyclerVvew.getChildLayoutPosition(v);
                                   VideoGalery.videoview.setVideoURI(Uri.parse(DataAdapterPostVideo.videolist.get(itemPosition).getMedia_path()));

               VideoGalery.videoview.start();
                VideoGalery.videoview.seekTo(500);

                VideoGalery.videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                    @Override
                    public void onPrepared(MediaPlayer mp) {
                       mp.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
                           @Override
                           public void onBufferingUpdate(MediaPlayer mp, int percent) {
                               if(percent==100)
                                   sm.hide();
                           }
                       });
                    }
                });
            }
        });
    }

除了progreccess栏和mediacontroller。当我想访问这两个元素时,我得到一个空访问错误。

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
    if (holder instanceof StudentViewHolder ) {

        Galery video= videolist.get(position);


        if(String.valueOf(video.getMime_type()).contains("video")) {
            ((StudentViewHolder) holder).titr.setText(String.valueOf(video.getTitel()));
            ((StudentViewHolder) holder).year.setText(String.valueOf(video.getPublish_at()));
            ((StudentViewHolder) holder).fi.setText(String.valueOf(video.getId()));
            ((StudentViewHolder) holder).thumbNail.setVideoURI(Uri.parse(video.getMedia_path()));
            ((StudentViewHolder) holder).progress_video.setVisibility(View.VISIBLE);
            ((StudentViewHolder) holder).thumbNail.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
                    mp.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
                        @Override
                        public void onBufferingUpdate(MediaPlayer mp, int percent) {
                            if(percent==100)
                                ((StudentViewHolder) holder).progress_video.setVisibility(View.GONE);
                        }
                    });
                }
            });
            ((StudentViewHolder) holder).thumbNail.seekTo(2000);

           // Log.i("Hamed",String.valueOf(video.getId()));
        }
       animate((StudentViewHolder) holder);

    } else {
        ((ProgressViewHolder) holder).progressBar.setIndeterminate(true);
    }
}

注意这些代码。在这些代码之后,我使用以下代码运行应用程序。我没有任何访问进度条的权限,我面临以下错误。

1 个答案:

答案 0 :(得分:0)

虽然可以通过仔细查看代码来解决这个问题。我想以不同的方式回答它。

观看NPE的原因如下:

  • 您要查找的视图在布局中不存在。
  • 您要查找的视图与您尝试的视图具有不同的ID 找到。
  • 该视图没有任何ID。