I am unable to call method startVideo() from another class. When I try to compile, I get the following error:
Cannot make a static reference to the non-static method findViewById(int) from the type Activity
Here is the startVideo() method code:
public static void startVideo(){
startButton = (Button) findViewById(R.id.start_btn);
startButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(width&g开发者_开发问答t;1000){
setContentView(R.layout.lesson_large);
}else{
setContentView(R.layout.lesson);
}
//@@@ FOR INTRO AV @@@//
VideoView videoView = (VideoView) findViewById(R.id.videoView1);
MediaController mediaControler = new MediaController(Main.this);
mediaControler.setAnchorView(videoView);
Uri introVideo = Uri.parse(statics.urlAv + "AV264.MP4");
videoView.setMediaController(mediaControler);
videoView.setVideoURI(introVideo);
videoView.start();
//@@@ FOR LESSON/SUBLESSSON AV @@@//
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
VideoView videoView = (VideoView) findViewById(R.id.videoView1);
MediaController mediaControler = new MediaController(Main.this);
mediaControler.setAnchorView(videoView);
Uri video = Uri.parse(statics.urlAv + "AV264.MP4");
videoView.setMediaController(mediaControler);
videoView.setVideoURI(video);
videoView.start();
}
});
}
});
menu();
exit();
}
Any help will really be appreciated. Thanks
you're calling findViewById which is not static method from your method which is static. instance methods can only be called on instance.
Either you should make it non-static, or create an instance of your class there and use it's findViewById
精彩评论