rumani rumani - 1 month ago 7
Java Question

Error: java.lang.UnsupportedOperationException: Not supported yet

Every time i press the Play button in mi app throws me the following error:

Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not supported yet.
at appjelic.AppJelic.actionPerformed(AppJelic.java:132)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.JToggleButton$ToggleButtonModel.setPressed(JToggleButton.java:308)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6516)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6281)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4872)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:747)
at java.awt.EventQueue.access$300(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:706)
at java.awt.EventQueue$3.run(EventQueue.java:704)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:720)
at java.awt.EventQueue$4.run(EventQueue.java:718)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:717)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)


Anyone know why?

I don't know why throws the error i don't know how to fix it.
I use NetBeans IDE with JDK 1.7 and vlcj library to play audio and video and jna library.

This is the code of mi app

public class AppJelic extends JPanel implements ActionListener{
Component video, video2;
String duracion;

String vlcPath="", mediaPath="", mediaPath2="";

private EmbeddedMediaPlayerComponent ourMediaPlayer,ourPlayer;

private static String OSArch = System.getProperty("os.arch").toLowerCase();

JFileChooser fileChooser = new JFileChooser();

boolean flag = false;

static AppJelic appJelic;

static char actual[][] = null;
static Long tmp = null;
static ArrayList<DatosMatriz> lista = new ArrayList<>();
static DatosMatriz dato = new DatosMatriz();

JCheckBox check1 = new JCheckBox();
JCheckBox check2 = new JCheckBox();
JCheckBox check3 = new JCheckBox();

JLabel label1 = new JLabel();
JLabel label2 = new JLabel();
JLabel label3 = new JLabel();

JButton boton = new JButton();

public AppJelic(){
setLayout(null);

check1.setText("Boca");
check1.setBounds(100, 100, 60, 30);
check1.addActionListener(this);
add(check1);

check2.setText("Video");
check2.setBounds(100, 140, 60, 30);
check2.addActionListener(this);
add(check2);

check3.setText("Audio");
check3.setBounds(100, 180, 60, 30);
check3.addActionListener(this);
add(check3);

label1.setBounds(180, 100, 120, 30);
add(label1);

label2.setBounds(180, 140, 120, 30);
add(label2);

label3.setBounds(180, 180, 180, 30);
add(label3);

boton.setText("Play!");
boton.setBounds(165, 240, 100, 30);
boton.addActionListener(this);
add(boton);

}

@Override
public void actionPerformed(ActionEvent e) {
String archivo = "";
if(e.getSource() == check1){
lista = abrirArchivo();
archivo = dato.getRuta();
label1.setText(archivo);
} else if (e.getSource() == check2){
archivo = abrirVideo();
label2.setText(archivo);
}else if (e.getSource() == check3){
try {
archivo = abrirAudio();
} catch (IOException ex) {
Logger.getLogger(AppJelic.class.getName()).log(Level.SEVERE, null, ex);
}
label3.setText(archivo);
}else if (e.getSource().equals(boton)){
flag=true;
if(ourMediaPlayer != null){
ourMediaPlayer.getMediaPlayer().stop();
}
if(ourPlayer != null){
ourPlayer.getMediaPlayer().stop();
}
audioVideo();
}
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public void paint(Graphics g){
int x = 120;
int y = 450;
int incremento = 20;
char simbolo = ' ';

super.paint(g);

Graphics2D g2d = (Graphics2D) g;

if (actual != null) {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {

simbolo = actual[i][j];

if (simbolo == '@') {
g2d.setColor(Color.BLACK);
} else if (simbolo == 'O') {
g2d.setColor(Color.GRAY);
}
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.fillOval(x + (j + 1) * incremento, y + (i + 1) * incremento, 15, 15);

}
}
}
}

public ArrayList<DatosMatriz> abrirArchivo() {
ArrayList<DatosMatriz> arrayDatos = new ArrayList<>();

if (check1.isSelected() == true) {
try {
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.showOpenDialog(this);
File abre = fileChooser.getSelectedFile();
if (abre != null) {

FileReader fr = new FileReader(abre);
BufferedReader br = new BufferedReader(fr);
String numero;

Float tiempo = null;
String valor;
Long tmp = null;

char[] array = new char[8];
int contador = 0;
int pos1 = 0;

while ((numero = br.readLine()) != null) {

char[][] matriz = new char[8][8];

for (int i = 0; i < 8; i++) {

array = numero.toCharArray();

pos1 = numero.indexOf(",");

if (pos1 == 20) {
valor = numero.substring(22, 25);
if (valor.charAt(2) == ')') {
valor = valor.substring(0, 2);
}
tiempo = Float.parseFloat(valor) * 1000;
tmp = tiempo.longValue();
dato.setTiempo(tmp);
}
for (int k = 2; k <= 16; k = k + 2) {
if (i == 0) {
matriz[i][contador] = array[k + 3];
} else {
matriz[i][contador] = array[k];
}

contador++;
}

contador = 0;
numero = br.readLine();

}

DatosMatriz datos = new DatosMatriz();
dato.setRuta(abre.getName());
datos.setMatriz(matriz);
datos.setTiempo(tmp);
arrayDatos.add(datos);

}
br.close();
}
} catch (Exception e) {
System.out.println(e);
}

}
return arrayDatos;
}

public String abrirVideo() {
String ruta = "";
if (check2.isSelected() == true) {
try {
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.showOpenDialog(this);
File abre = fileChooser.getSelectedFile();
mediaPath = abre.getAbsolutePath();

NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), vlcPath);

ruta += abre.getName();
ourMediaPlayer = new EmbeddedMediaPlayerComponent();

video = ourMediaPlayer.getComponent(0);

video.setBounds(2, 300, 430, 150);

} catch (Exception ex) {
Logger.getLogger(AppJelic.class.getName()).log(Level.SEVERE, null, ex);
}

} else {
video.setVisible(false);
ourMediaPlayer.getMediaPlayer().stop();
}
return ruta;
}

public String abrirAudio() throws IOException {
String ruta3 = "";

if (check3.isSelected() == true) {
try {
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.showOpenDialog(this);
File abre = fileChooser.getSelectedFile();
mediaPath2 = abre.getAbsolutePath();

NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), vlcPath);

ruta3 += abre.getName();

ourPlayer = new EmbeddedMediaPlayerComponent();
video2 = ourPlayer.getComponent(0);

} catch (HeadlessException e) {
System.out.println(e);
}
} else {
video2.setVisible(false);
ourPlayer.getMediaPlayer().stop();
}
return ruta3;
}

public void reproducir() {

while (flag) {
for (int i = 0; i < lista.size(); i++) {
dato = lista.get(i);
actual = dato.getMatriz();
tmp = dato.getTiempo();

repaint();

try {
Thread.sleep(tmp);
} catch (InterruptedException ex) {
Logger.getLogger(AppJelic.class.getName()).log(Level.SEVERE, null, ex);
}
}
if (check3.isSelected() == true) {
ourPlayer.getMediaPlayer().addMediaPlayerEventListener(new MediaPlayerEventAdapter() {
@Override
public void finished(MediaPlayer mediaplayer) {
flag = false;
}
});
} else {
flag = false;
}

}

}

public void audioVideo() {
if (video != null) {
add(video);
ourMediaPlayer.getMediaPlayer().playMedia(mediaPath);

}

if (video2 != null) {
add(video2);
ourPlayer.getMediaPlayer().playMedia(mediaPath2);
}
}

public static void main(String[] args) {
JFrame frame = new JFrame("Jelic");
AppJelic jelic = new AppJelic();
jelic.audioVideo();
frame.add(jelic);
frame.setSize(450, 700);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

while (true) {
jelic.reproducir();
}
}


}

thanks for your help!

Answer

Very simple; have a look at your actionPerformed() method. It says:

throw new UnsupportedOperationException("Not supported yet."); //To change body of generated 

And surprise, that throws an exception at you. Unconditionally, as last step upon processing that other "action" code. Always.

That statement was probably created by your IDE. Just remove that line!

The default behavior of many IDEs is to generate new code for you; but then they have to put in something. And either your IDE (or the person that started writing that code put that exception into that method body to indicate: "here work todo"). And then you simply forgot to remove that throw statement!

And hint: if you really don't know what that line is doing; then I recommend to step back from doing UI programming. Then you should better spend the next week learning about such absolute java basics. Otherwise, you will run from one problem into the next one. Don't try to run when you can hardly crawl!