所以,我有这个代码
public class MultiThreadedWindow extends JFrame implements ActionListener {
FormatRtsp parser = new FormatRtsp();
private JPanel topPanel = new JPanel();
private JPanel statusPanel = new JPanel();
private JButton btnPlay = new JButton("Conectar");
private JButton btnStop = new JButton("Desconectar");
private JButton btnPause = new JButton("Pausar");
private MediaPlayerFactory[] factory;
private EmbeddedMediaPlayer[] mediaPlayer;
int Video_Width = 500;
int Video_Height = 300;
int Num_Video = 4;
public MultiThreadedWindow() {
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setLayout(new BorderLayout());
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Canvas[] videoCanvas = new Canvas[Num_Video];
JPanel mainPanel = new JPanel(new FlowLayout());
JPanel[] vidPanel = new JPanel[Num_Video];
for (int i = 0; i < Num_Video; i++) {
vidPanel[i] = new JPanel();
videoCanvas[i] = new Canvas();
vidPanel[i].setPreferredSize(new Dimension(Video_Width, Video_Height));
vidPanel[i].setBackground(Color.black);
vidPanel[i].setLayout(new BorderLayout());
videoCanvas[i].setBackground(Color.black);
vidPanel[i].add(videoCanvas[i], BorderLayout.CENTER);
mainPanel.add(vidPanel[i]);
}
这是一个使用 VLCj 显示 4 个摄像机的项目。我试图研究文档,甚至在 Stackoverflow 中通过多个流看到它,但我发现它令人困惑。我研究了很多,但无法确定空指针异常在哪里。
它应该显示一个带有 4 个画布的 JFrame。我能够执行相同的代码声明 4 个工厂和 4 个媒体播放器,但我认为这不是正确的方法。我想了解我缺少什么。谢谢你。
错误:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at core.MultiThreadedWindow.<init>(MultiThreadedWindow.java:56)
慕容森
相关分类