每次按下mi app中的“播放”按钮都会引发以下错误:
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)
任何人都知道为什么?
我不知道为什么抛出错误我不知道如何解决它。 我使用带有JDK 1.7和vlcj库的NetBeans IDE来播放音频和视频以及jna库。
这是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();
}
}
}
感谢您的帮助!
答案 0 :(得分:3)
很简单;看看你的 actionPerformed()方法。它说:
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated
令人惊讶的是,这会引发异常。无条件地,作为处理其他“动作”代码的最后一步。总是
该声明可能是由您的IDE创建的。只需删除该行!
许多IDE的默认行为是为您生成新代码;但他们必须投入一些东西。并且您的IDE(或者开始编写该代码的人将该异常放入该方法体中以指示:“here work todo”)。然后你只是忘了删除那个抛出语句!
提示:如果你真的不知道那条线在做什么;然后我建议退一步进行UI编程。然后你最好在下周学习这种绝对的java基础知识。否则,您将从一个问题运行到下一个问题。当你几乎无法爬行时,不要试图跑!
答案 1 :(得分:0)
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.
}
无论结果如何,您方法的最后一个语句都会抛出此异常。删除该行,看看是否能解决问题!