为什么videoview明明已经获得路径可是在setvideopath那里会报错?
public class VideoListActivity extends ListActivity{
private int currentListItme = 0;
public Cursor mCursor = null;
public MediaPlayer mMediaPlayer = null;
public Button zhuangzai=null;
public Button play=null;
public Button pause=null;
public VideoView videoView;
public String path;
private List<String> videoNameList = new ArrayList<String>();
private List<String> videoPathList = new ArrayList<String>();
public Cursor getAllVideos() {
ContentResolver contentResolver = getContentResolver();
Cursor cursor = contentResolver.query(
MediaStore.Video.Media.EXTERNAL_CONTENT_URI, null, null, null,
MediaStore.Video.Media.DEFAULT_SORT_ORDER);
return cursor;
}
public List<String> getAllVideosName(){
List<String> names=new ArrayList<String>();
if(mCursor!=null&&mCursor.moveToFirst()){
do{
String name=mCursor.getString(mCursor.getColumnIndex(MediaStore.Video.Media.TITLE));
names.add(name);
}while(mCursor.moveToNext());
}
return names;
}
public List<String> getAllVideoUri(){
List<String> uris=new ArrayList<String>();
if(mCursor!=null&&mCursor.moveToFirst()){
do{
String uri=mCursor.getString(mCursor.getColumnIndex(MediaStore.Video.Media.DATA));
uris.add(uri);
}while(mCursor.moveToNext());
}
return uris;
}
public void onListItemClick(ListView l, View v, int position, long id) {
currentListItme = position;
path= videoPathList.get(position);
super.onListItemClick(l, v, position, id);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videolist);
// musicList();
mCursor=getAllVideos();
videoNameList=getAllVideosName();
videoPathList=getAllVideoUri();
zhuangzai=(Button)findViewById(R.id.button1);
play=(Button)findViewById(R.id.button2);
pause=(Button)findViewById(R.id.button3);
zhuangzai.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
/* 设置路径 */
Toast.makeText(VideoListActivity.this,"路径是:"+ path, Toast.LENGTH_SHORT).show();
videoView.setVideoPath(path);
/* 设置模式-播放进度条 */
videoView.setMediaController(new MediaController(VideoListActivity.this));
videoView.requestFocus();
}
});
为什么会报错
01-13 09:29:05.932: E/AndroidRuntime(4353): java.lang.NullPointerException
01-13 09:29:05.932: E/AndroidRuntime(4353): at com.example.media.VideoListActivity$1.onClick(VideoListActivity.java:94)
94行是videoView.setVideoPath(path);