android - Why am i getting a NullPointer? -


i m trying create videoplayer getting videos path in sdcard.unfortunately m getting nullpointer!could please me?? code:

class videofilter implements filenamefilter {     public boolean accept(file dir, string name) {         return (name.endswith(".wmv"));     } } public class video extends listactivity {      private static final string media_path = new string("/sdcard/videodata/");     private list<string> songs = new arraylist<string>();     arrayadapter<string> videolist ;     file home = new file(media_path); private videoview mvideoview;      @override     public void oncreate(bundle icicle) {              try {                 super.oncreate(icicle);                 setcontentview(r.layout.main3);                 updatevideolist();             } catch (nullpointerexception e) {                 log.v(getstring(r.string.app_name), e.getmessage());             }       }      private void updatevideolist() {         // todo auto-generated method stub          if (home.listfiles( new videofilter()).length > 0) {             (file file : home.listfiles( new videofilter())) {                 songs.add(file.getname());             }     videolist = new arrayadapter<string>(this,r.layout.video_item,songs);              setlistadapter(videolist);         }     }      @override     protected void onlistitemclick(listview l, view v, int position, long id) {            mvideoview.setvideopath(media_path + songs.get(position));         mvideoview.setmediacontroller(new mediacontroller(this));         mvideoview.requestfocus();     }  } 

@martin if that

@override     protected void onlistitemclick(listview l, view v, int position, long id) {          setcontentview(r.layout.main2);         mvideoview = (videoview) findviewbyid(r.id.videoview);          mvideoview.setvideopath(media_path + songs.get(position));         mvideoview.setmediacontroller(new mediacontroller(this));         mvideoview.requestfocus();     } 

then m getting 07-03 15:55:55.190: error/androidruntime(4090): java.lang.runtimeexception: content must have listview id attribute 'android.r.id.list'

edit:

public class mainscreen extends activity {      bundle extras = getintent().getextras();     final int videos = extras.getint("video");       private videoview mvideoview;     string k= new integer(videos).tostring();     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          setcontentview(r.layout.main2);          mvideoview = (videoview) findviewbyid(r.id.videoview);         mvideoview = (videoview) findviewbyid(r.id.video);         mvideoview.setvideopath(k);         mvideoview.setmediacontroller(new mediacontroller(this));         mvideoview.requestfocus();          } 

thats way m passing path string first activity t second not working.............

you need fetch videoview first:

mvideoview = (videoview) findviewbyid(r.id.myvideoview); 

edit

your content must have listview id attribute 'android.r.id.list'. it's simple that. in main2.xml need listview id 'list'.

edit2

so want rid of listview play video. i'd recommend indeed starting new activity this. listactivity doesn't allow contents without listview.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -