1

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>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

1
  • Tabs make the code block unhappy. You should try spaces instead. Commented Aug 31, 2011 at 6:17

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.