Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: What is wrong with my code

  1. #1
    Junior Member
    Join Date
    Nov 2019
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default What is wrong with my code

    Hi, I am a beginner at Java and was simply making some controls. However whenever i try and open in chrome i get an error in the console saying "Uncaught TypeError: Cannot read property 'addEventListener' of null
    at HTMLDocument.initialiseWebPage (VideoScript.js:26)" pointing to this line
     playButton.addEventListener ( "click", PlayPause );
    . Thanks for your help in advance


    document.addEventListener('DOMContentLoaded', initialiseWebPage);
    ///explanation
     
    function initialiseWebPage()
    {
    	const myVideo = document.querySelector ( "video" );
    	myVideo.removeAttribute( "controls" );
    	const playButton = document.getElementById ("playPause");
     
     
    	function PlayPause()
    	{
    		if (myVideo.paused === true)
    		{
    			myVideo.play();
    			//
    			playButton.innerHTML = "Pause";
    		}
    		else
    		{
    			myVideo.pause();
    		playButton.innerHTML = "Play";
    		}
    	}
    	playButton.addEventListener ( "click", PlayPause );
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,994
    Thanks
    53
    Thanked 2,445 Times in 2,396 Posts

    Default Re: What is wrong with my code

    Javascript is not the same as java

    Make sure playButton is not null.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Help! What is wrong with this code?
    By Hemu in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 6th, 2014, 08:40 AM
  2. What is wrong with my code
    By samapple789 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: February 16th, 2014, 11:04 AM
  3. What's wrong with my code?
    By shen in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 18th, 2013, 06:34 AM
  4. What's wrong with my code?
    By cbplayer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 13th, 2013, 03:07 PM
  5. what's wrong with my code?
    By vanitha in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 1st, 2012, 07:23 AM