
java提示 未报告的异常错误FileNotFoundException和JavaLayerException; 必须对其进行捕获或声明以便抛出
importjavax.swing.*;importjavax.swing.filechooser.FileNameExtensionFilter;importjava....
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.util.*;
import javazoom.jl.player.*;
import javazoom.jl.decoder.JavaLayerException;
public class mplay
{static int i=0;
public static void main(String[] args) throws FileNotFoundException,JavaLayerException
{JFrame jf=new JFrame("音乐播放器");
JButton dk=new JButton("打开"),bf=new JButton("播放");
JTextField gq=new JTextField(20);
String fl=new String();
BufferedInputStream music[];
jf.setSize(600,200);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setLayout(new FlowLayout());
jf.add(dk);jf.add(gq);jf.add(bf);
JFileChooser open=new JFileChooser();
FileNameExtensionFilter filter=new FileNameExtensionFilter("mp3&wav","mp3","wav");
open.setFileFilter(filter);
dk.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e)
{i=open.showOpenDialog(jf);}});
if(i==JFileChooser.APPROVE_OPTION)
{
fl=open.getSelectedFile().getAbsolutePath()+open.getSelectedFile().getName();
gq.setText(fl);
File file=new File(fl);
bf.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e)
{new Player(new BufferedInputStream(new FileInputStream(file))).play();}});
}
}
} 展开
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.util.*;
import javazoom.jl.player.*;
import javazoom.jl.decoder.JavaLayerException;
public class mplay
{static int i=0;
public static void main(String[] args) throws FileNotFoundException,JavaLayerException
{JFrame jf=new JFrame("音乐播放器");
JButton dk=new JButton("打开"),bf=new JButton("播放");
JTextField gq=new JTextField(20);
String fl=new String();
BufferedInputStream music[];
jf.setSize(600,200);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setLayout(new FlowLayout());
jf.add(dk);jf.add(gq);jf.add(bf);
JFileChooser open=new JFileChooser();
FileNameExtensionFilter filter=new FileNameExtensionFilter("mp3&wav","mp3","wav");
open.setFileFilter(filter);
dk.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e)
{i=open.showOpenDialog(jf);}});
if(i==JFileChooser.APPROVE_OPTION)
{
fl=open.getSelectedFile().getAbsolutePath()+open.getSelectedFile().getName();
gq.setText(fl);
File file=new File(fl);
bf.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e)
{new Player(new BufferedInputStream(new FileInputStream(file))).play();}});
}
}
} 展开
1个回答
展开全部
说明你调用了某些方法,而这些方法可能抛出FileNotFoundException和JavaLayerException异常,你必须对可能抛出的异常作处理,要么重新抛出,要么用try catch捕获。
追问
试过了,没用,帮我看看,改改,拜托了。
追答
这是java基础部分的知识,请先看你的教材的异常处理部分,搞清楚异常是做什么的,该怎么处理异常,然后再来提问,否则大家都是在浪费时间。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询