ERROR DE ImageIcon
Publicado por cristian almeida (2 intervenciones) el 22/05/2010 05:59:38
buenas noches este es mi codigo
SI ALGUIEN ME ME PUEDE AYUDAR SE LO AGRADECERIA MUCHO !!
package cargarimagenyescalar2;
import javax.swing.JApplet;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.Timer;
public class AnimadorLogo extends JApplet implements ActionListener {
private final static String NOMBRE_IMAGEN="crs";
protected ImageIcon imagenes[];
private int imagenesTotales=97;
private int imagenActual=0;
private int retrasoAnimacion=50;
private int anchura;
private int altura;
private Timer temporizadorAnimacion;//el objeto timer controla la animacion
//inicializar objeto animadorlogo cargando las imagenes
public AnimadorLogo() {
imagenes= new ImageIcon[imagenesTotales];
for(int cuenta=0;cuenta<imagenes.length;++cuenta)
imagenes[cuenta]= new ImageIcon(getClass().getResource(//AQUI ME SALE ERROR
"imagenes/"+NOMBRE_IMAGEN+cuenta+".gif"));//at cargarimagenyescalar2.AnimadorLogo.<init>(AnimadorLogo.java:29)
//todas las imagenes tienen la misma anchura y altura
anchura=imagenes[0].getIconWidth();
altura=imagenes[0].getIconHeight();
}
//mostrar imagen actual
public void paintComponent(Graphics g) {
super.paintComponents(g);
imagenes[imagenActual].paintIcon(this, g, 0,0);
//pasar ala siguiente imagen solo si el temporizador se esta ejecutando
if(temporizadorAnimacion.isRunning())
imagenActual=(imagenActual+1)% imagenesTotales;
}
public void init() {
}
public void actionPerformed(ActionEvent eventoAccion) {
repaint();//pintar el animador nuevamente
//throw new UnsupportedOperationException("Not supported yet.");
}
//iniciar o reiniciar
public void iniciarAnimacion() {
if(temporizadorAnimacion == null) {
imagenActual=0;
temporizadorAnimacion= new Timer(retrasoAnimacion,this);
temporizadorAnimacion.start();
}
else//continuar desde la ultima imagen mostrada
if(! temporizadorAnimacion.isRunning())
temporizadorAnimacion.restart();
}
//detener el temporizador de la animacion
public void detenerAnimacion() {
temporizadorAnimacion.stop();
}
//devolver el tamaño minimo de la animacion
public Dimension getMinimumSize() {
return getPreferredSize();
}
//devolver el tamaño preferido de la animacion
public Dimension getPreferredSize() {
return new Dimension (anchura,altura);
}
//ejecutar la animacion en un objeto Jframe
public static void main (String args[]) {
AnimadorLogo animacion=new AnimadorLogo();// AQUI ME SALE OTRO ERROR at cargarimagenyescalar2.AnimadorLogo.main(AnimadorLogo.java:81)
JFrame ventana=new JFrame("Christian Almeida Producciones");//configuarar ventana
ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container contenedor=ventana.getContentPane();
contenedor.add(animacion);
ventana.pack();//hacer una ventana suficientemente grande para su GUI
ventana.setVisible(true);//mostrar la ventana
animacion.iniciarAnimacion();//comenzar animacion
}//fin del metodo main
}//fin dela clase animacion logo
debug:
Have no FileObject for C:\Archivos de programa\Java\jdk1.6.0_20\jre\lib\sunrsasign.jar
Have no FileObject for C:\Archivos de programa\Java\jdk1.6.0_20\jre\classes
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:167)
at cargarimagenyescalar2.AnimadorLogo.<init>(AnimadorLogo.java:29)
at cargarimagenyescalar2.AnimadorLogo.main(AnimadorLogo.java:81)
Java Result: 1
BUILD SUCCESSFUL (total time: 10 seconds)
SI ALGUIEN ME ME PUEDE AYUDAR SE LO AGRADECERIA MUCHO !!
package cargarimagenyescalar2;
import javax.swing.JApplet;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.Timer;
public class AnimadorLogo extends JApplet implements ActionListener {
private final static String NOMBRE_IMAGEN="crs";
protected ImageIcon imagenes[];
private int imagenesTotales=97;
private int imagenActual=0;
private int retrasoAnimacion=50;
private int anchura;
private int altura;
private Timer temporizadorAnimacion;//el objeto timer controla la animacion
//inicializar objeto animadorlogo cargando las imagenes
public AnimadorLogo() {
imagenes= new ImageIcon[imagenesTotales];
for(int cuenta=0;cuenta<imagenes.length;++cuenta)
imagenes[cuenta]= new ImageIcon(getClass().getResource(//AQUI ME SALE ERROR
"imagenes/"+NOMBRE_IMAGEN+cuenta+".gif"));//at cargarimagenyescalar2.AnimadorLogo.<init>(AnimadorLogo.java:29)
//todas las imagenes tienen la misma anchura y altura
anchura=imagenes[0].getIconWidth();
altura=imagenes[0].getIconHeight();
}
//mostrar imagen actual
public void paintComponent(Graphics g) {
super.paintComponents(g);
imagenes[imagenActual].paintIcon(this, g, 0,0);
//pasar ala siguiente imagen solo si el temporizador se esta ejecutando
if(temporizadorAnimacion.isRunning())
imagenActual=(imagenActual+1)% imagenesTotales;
}
public void init() {
}
public void actionPerformed(ActionEvent eventoAccion) {
repaint();//pintar el animador nuevamente
//throw new UnsupportedOperationException("Not supported yet.");
}
//iniciar o reiniciar
public void iniciarAnimacion() {
if(temporizadorAnimacion == null) {
imagenActual=0;
temporizadorAnimacion= new Timer(retrasoAnimacion,this);
temporizadorAnimacion.start();
}
else//continuar desde la ultima imagen mostrada
if(! temporizadorAnimacion.isRunning())
temporizadorAnimacion.restart();
}
//detener el temporizador de la animacion
public void detenerAnimacion() {
temporizadorAnimacion.stop();
}
//devolver el tamaño minimo de la animacion
public Dimension getMinimumSize() {
return getPreferredSize();
}
//devolver el tamaño preferido de la animacion
public Dimension getPreferredSize() {
return new Dimension (anchura,altura);
}
//ejecutar la animacion en un objeto Jframe
public static void main (String args[]) {
AnimadorLogo animacion=new AnimadorLogo();// AQUI ME SALE OTRO ERROR at cargarimagenyescalar2.AnimadorLogo.main(AnimadorLogo.java:81)
JFrame ventana=new JFrame("Christian Almeida Producciones");//configuarar ventana
ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container contenedor=ventana.getContentPane();
contenedor.add(animacion);
ventana.pack();//hacer una ventana suficientemente grande para su GUI
ventana.setVisible(true);//mostrar la ventana
animacion.iniciarAnimacion();//comenzar animacion
}//fin del metodo main
}//fin dela clase animacion logo
debug:
Have no FileObject for C:\Archivos de programa\Java\jdk1.6.0_20\jre\lib\sunrsasign.jar
Have no FileObject for C:\Archivos de programa\Java\jdk1.6.0_20\jre\classes
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:167)
at cargarimagenyescalar2.AnimadorLogo.<init>(AnimadorLogo.java:29)
at cargarimagenyescalar2.AnimadorLogo.main(AnimadorLogo.java:81)
Java Result: 1
BUILD SUCCESSFUL (total time: 10 seconds)
Valora esta pregunta


0