0

This programs take in a string for a parameter. Currently filled with:

"http://localhost/media/svu.mp4"

I have made sure the URL exists.

I am using the VLCj library to create the mediaPlayerComponent (which is placed inside the container (JPanel mainPanel) ). The component mainPanel is then placed inside the JLayeredPanel layers. On top of that, I place a clear (non-opaque) layer (JPanel glassPane). According to everything I've read, this should be working and Eclipse isn't showing any errors or warnings.

The stack trace is as follows:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
   at client.test.Client.<init>(Client.java:62)
   at client.test.Client$1.run(Client.java:44)
   at java.awt.event.InvocationEvent.dispatch(Unknown Source)
   at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
   ....

The code is below. Line 62 is marked with a comment. The JPanels and JLayeredPanel, as well as the windowDimensions are all created as static objects above the main method in my code.

Any and all help is greatly appreciated.

static JLayeredPane layers = new JLayeredPane();
static JPanel mainPanel, glassPane = new JPanel();

public Client(String toPlay) {
    JFrame frame = new JFrame("Client");
    mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
    MediaPlayer mediaPlayer= mediaPlayerComponent.getMediaPlayer();

    frame.setSize(windowDimensions[0], windowDimensions[1]);
    frame.setLayout(new BorderLayout());
    frame.setExtendedState(frame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
    frame.setResizable(false);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       
    frame.add(layers, BorderLayout.CENTER);

    layers.setBounds(0,0,windowDimensions[0], windowDimensions[1]);
    mainPanel.setBackground(Color.black); /* This is line 62 */
    mainPanel.setBounds(0,0,windowDimensions[0], windowDimensions[1]);
    mainPanel.setOpaque(true);
    mainPanel.add(mediaPlayerComponent);

    glassPane.setBackground(Color.white);
    glassPane.setBounds(0,0,windowDimensions[0], windowDimensions[1]);
    glassPane.setOpaque(false);

    layers.add(mainPanel, new Integer(0), 0);
    layers.add(glassPane, new Integer(1), 0);

    frame.setVisible(true);
    mediaPlayer.playMedia(toPlay);
}
2
  • What is at (Client.java:62) line no? Commented May 30, 2014 at 18:08
  • Marked by comment /*This is line 62 */ Commented May 30, 2014 at 18:11

2 Answers 2

2

mainPanel has not been intitialized, even if it looks like it has. You have this code:

static JPanel mainPanel, glassPane = new JPanel();

This only inititalzes glassPane. In order to initialize mainPanel you have to change your code to this:

static JPanel mainPanel = new JPanel(), glassPane = new JPanel();
Sign up to request clarification or add additional context in comments.

2 Comments

I'm gonna choose @David Xu for best answer because he called it first, but you're absolutely correct. Execution went without a hitch! Thanks a lot guys!
@NickMedovich As you should, he beat me to it :).
1

You haven't initialized mainPanel. Try adding mainPanel = new JPanel(); above the error line.

You'll also need to call frame.add(mainPanel); after you initialize the panel.

4 Comments

I initialize each of the panels statically above the main method: JPanel mainPanel, glassPane = new JPanel();
The only way that line is throwing an NPE is if mainPanel is null.
Well at least the form is showing now. Adding the mainPanel initialization to its own line made the form show up. Now I just have to figure out why the video isn't loading. Thank you very much!!
And just to throw it out there, I don't add the mainPanel to the frame at all. I add the mainPanel to the JLayeredPanel, add the glassPane on top, then add the whole JLayeredPanel to the frame.

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.