Hi I’m trying to display a video from a list and I keep getting the null pointer exception any ideas why?
This is my code:
public class HallList extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(ArrayAdapter.createFromResource(getApplicationContext(),
R.array.lecturehalls ,R.layout.list_item));
getListView().setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if (position == 0)
{ video(position);
}
else if(position == 1)
{
video(position);
}
}
});
}
private void video(int position){
MediaController mediaController = new MediaController(this);
VideoView videoView = (VideoView) findViewById(R.id.video);
if (position == 0){
//example path
String path0="http://www.pocketjourney.com/downloads/pj/video/famous.3gp";
mediaController.setMediaPlayer(videoView);
videoView.setVideoPath(path0);
videoView.setMediaController(mediaController);
videoView.requestFocus();
videoView.start();
mediaController.show(); }
else if( ........ ){...}
}
}
I’m not sure of my way of doing it right..If there’s an easier way to do it could you please help me with it..I saw a tutorial displaying web links from a list..I want to create it the same way but don’t seem to get how its done with list of video links?
this is the tutorial: http://mobile.tutsplus.com/tutorials/android/android-listview/
Thanx 🙂
In which xml file you define your VideoView? Without
setContentView()your are defining your videoView(Without seeing your error log I am guessing) I think this line cause nullPointerException,
You have to define VIideoView in your xml file and set that xml file as a
setContentView(main.xml)also put this line after setContentView() in onCreate() of your activity..