jFrame GetGraphics имеет значение null в Java во время рисования изображения

Я получаю нулевую ошибку исключения при рисовании изображения в jframe. я отлаживаю код и проверяю, что изображение и фрейм не равны NULL, но все равно выдает исключение NULL при рисовании изображения в фрейм.

Пожалуйста, посмотрите:

public void run(){
    try{

        ObjectInputStream objVideoIn = new ObjectInputStream(serVideoIn);
        byte[] imgbytes=null;
        ByteArrayInputStream barrin=null;


        JFrame jf = new JFrame();
        Graphics ga=jf.getGraphics(); //Getting null exception 
                //Thread.sleep(10000);
        jf.setVisible(true);
        jf.setSize(400, 400);


        while(true){
                    int index=0;
                    //Thread.sleep(300);
                    int size= (int)objVideoIn.readObject();
                    imgbytes = new byte[size];
                    barrin = new ByteArrayInputStream(imgbytes);
                    System.out.println("image size" + size);
                    //Thread.sleep(200);
                    while(index<size)
                    {
                        System.out.println("reading image");
                        int bytesread = objVideoIn.read(imgbytes, index, size-index);
                        if(bytesread<0){
                            System.out.println("error in receiving bytes yar");
                        }
                        index+=bytesread;
                    }
                    //barrin.read(imgbytes, 0, imgbytes.length);
                    barrin = new ByteArrayInputStream(imgbytes);

                    buffImg = ImageIO.read(barrin);

                        if(buffImg==null)
                        {
                            System.out.println("null received");
                        }
                        else {
                            System.out.println("image received");

                        **ga.drawImage(buffImg, 0, 0, null);**


                        }
                    }

            }
    }
    catch(Exception ex)
    {
        System.out.println("error reading video" +ex.getMessage());
    }

}

Ответы на вопрос(1)

Ваш ответ на вопрос