2016-07-28 66 views
0

我有喜歡的視頻視圖,文本視圖和佈局的一些對象,以便對就這樣產生了:不能訪問到進度條的其他活動

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

注意這些代碼。在這些代碼之後,我使用以下代碼運行應用程序。我沒有進度條的任何訪問權限,我面臨着下面的錯誤。

回答

0

雖然這可以通過仔細看看你的代碼來解決。我想以不同的方式回答。

NPE上的觀點來由於原因,如:

  • 你正在努力尋找的看法是不存在的佈局。
  • 您嘗試查找的視圖與您正在嘗試查找的 的ID不同。
  • 該視圖沒有任何標識。