所以,我有这个代码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)
1 回答
慕容森
TA贡献1853条经验 获得超18个赞
您在第 56 行看到 NPE,因为您尚未在第 10 行(以及第 9 行)初始化数组。
其他代码使用类成员而不是数组来保存它们。
private MediaPlayerFactory factory0, factory1, factory2, factory3;
private EmbeddedMediaPlayer mediaPlayer0, mediaPlayer1, mediaPlayer2, mediaPlayer3;
添加回答
举报
0/150
提交
取消