Boa tarde pessoal estou desenvolvendo uma aplicação e estou precisando criar uma classe que pegue um numero X de fotos e transforme em um VIDEO , peguei esse código de um livro mas ele sempre da null pointer , não sei mecher muito bem com a parte de debug mas acho que alguem com experiência só vendo o código vai poder me ajudar !!
MAIN
package photosconverter;
import javax.swing.JFrame;
public class LogoAnimator
{
public static void main( String args[] )
{
LogoAnimatorJPanel animation = new LogoAnimatorJPanel();
JFrame window = new JFrame( "Inter" );
window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
window.add( animation );
window.pack();
window.setVisible( true );
animation.startAnimation();
}
}
CLASSE 2
package photosconverter;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;
public class LogoAnimatorJPanel extends JPanel
{
private final static String IMAGE_NAME = “teste”;
protected ImageIcon images[];
private final int TOTAL_IMAGES = 1;
private int currentImage = 0;
private final int ANIMATION_DELAY = 50;
private int width;
private int height;
private Timer animationTimer;
public LogoAnimatorJPanel()
{
images = new ImageIcon[ TOTAL_IMAGES ];
for ( int count = 0; count < images.length; count++ )
images[count] = new ImageIcon(getClass().getResource(
"images/" + IMAGE_NAME + count + ".jpeg" ));
width = images[ 0 ].getIconWidth();
height = images[ 0 ].getIconHeight();
}
public void paintComponent( Graphics g )
{
super.paintComponent( g );
images[ currentImage ].paintIcon( this, g, 0, 0 );
if (animationTimer.isRunning())
currentImage = ( currentImage + 1 ) % TOTAL_IMAGES;
}
public void startAnimation()
{
if ( animationTimer == null )
{
currentImage = 0;
animationTimer =
new Timer( ANIMATION_DELAY, new TimerHandler() );
animationTimer.start();
}
else
{
if ( ! animationTimer.isRunning())
animationTimer.restart();
}
}
public void stopAnimation()
{
animationTimer.stop();
}
public Dimension getMinimumSize()
{
return getPreferredSize();
}
public Dimension getPreferredSize()
{
return new Dimension( width, height );
}
private class TimerHandler implements ActionListener
{
public void actionPerformed( ActionEvent actionEvent )
{
repaint();
}
}
}
Criei um pacote IMAGES e dentro dele coloquei 2 fotos , teste0.jpeg e teste1.jpeg …
E da o seguinte erro :
Exception in thread “main” java.lang.NullPointerException
at javax.swing.ImageIcon.(ImageIcon.java:167)
at photosconverter.LogoAnimatorJPanel.(LogoAnimatorJPanel.java:29)
at photosconverter.LogoAnimator.main(LogoAnimator.java:10)
Java Result: 1
CONSTRUÍDO COM SUCESSO (tempo total: 0 segundos)
o erro seria bem abaixo do for pelo que eu entendi mas ja tentei de todas as formas e nao tive exito na depuração
Agradeço qualquer ajuda , vou ficar online até as 8 , e irei responder qualquer duvida sobre a aplicação …
Att;
Lukas Souza