大家帮忙看看,用java编写的简易音频播放器有错误 5

importjava.awt.BorderLayout;importjava.awt.Dimension;importjava.awt.event.ActionEvent... import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class MainFrame extends JFrame {
private JPanel contentPane;

private JTextField jTextField1 = new JTextField();
private JLabel jLabel1 = new JLabel();
private JPanel jPanel1 = new JPanel();
private JButton jButton1 = new JButton();
private JButton jButton2 = new JButton();
private java.applet.AudioClip clip;
public MainFrame() throws Exception
{
jbInit();
}
private void jbInit() throws Exception {
//setIconImage(Toolkit.getDefaultToolkit().createImage(MainFrame.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
this.setSize(new Dimension(418, 118));
this.setTitle("JSoundDemo1");

jLabel1.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel1.setToolTipText("");
jLabel1.setText("Waiting.........");

jButton1.setFont(new java.awt.Font("Dialog", 0, 12));
jButton1.setText("Play");
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jButton2.setEnabled(false);
jButton2.setFont(new java.awt.Font("Dialog", 0, 12));
jButton2.setText("Stop");
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}
});
jTextField1.setText(ClassLoader.getSystemResource("sounds/springmusic.au").toString());
contentPane.add(jLabel1, BorderLayout.SOUTH);
contentPane.add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jButton1, null);
jPanel1.add(jButton2, null);
contentPane.add(jTextField1, BorderLayout.NORTH);

clip=null;
}
void jButton1_actionPerformed(ActionEvent e) {
try{
jButton1.setEnabled(false);
jButton2.setEnabled(true);
clip = java.applet.Applet.newAudioClip(new java.net.URL(this.jTextField1.getText()));
clip.play();
this.jLabel1.setText("Now Playing "+this.jTextField1.getText());
}catch(Exception err){
err.printStackTrace();
}
}
void jButton2_actionPerformed(ActionEvent e) {
try{
jButton1.setEnabled(true);
jButton2.setEnabled(false);
clip.stop();
this.jLabel1.setText("Waiting .......");
}catch(Exception err){
err.printStackTrace();
}
}
}

错误:
Exception in thread "main" java.lang.NullPointerException
at MainFrame.jbInit(MainFrame.java:51)
at MainFrame.<init>(MainFrame.java:24)
at MainFrame.main(MainFrame.java:83)

代码从书上复制的,不知要怎么改,本人是刚学java的
展开
 我来答
hct5604142
2011-04-30 · TA获得超过439个赞
知道答主
回答量:58
采纳率:0%
帮助的人:28.8万
展开全部
好穗闹吧,我直接把灶颤路径名给你改掉看答案猜辩罩吧
package PressTest;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class MainFrame extends JFrame {

private JPanel contentPane;
private JTextField jTextField1 = new JTextField();
private JLabel jLabel1 = new JLabel();
private JPanel jPanel1 = new JPanel();
private JButton jButton1 = new JButton();
private JButton jButton2 = new JButton();
private java.applet.AudioClip clip;
public static void main(String[] args) throws Exception{
MainFrame mf=new MainFrame();
mf.setVisible(true);
}
public MainFrame() throws Exception {
jbInit();

}

private void jbInit() throws Exception {
//setIconImage(Toolkit.getDefaultToolkit().createImage(MainFrame.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
this.setSize(new Dimension(418, 118));
this.setTitle("JSoundDemo1");

jLabel1.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel1.setToolTipText("");
jLabel1.setText("Waiting.........");

jButton1.setFont(new java.awt.Font("Dialog", 0, 12));
jButton1.setText("Play");
jButton1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jButton2.setEnabled(false);
jButton2.setFont(new java.awt.Font("Dialog", 0, 12));
jButton2.setText("Stop");
jButton2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}
});
jTextField1.setText("毛".toString());
contentPane.add(jLabel1, BorderLayout.SOUTH);
contentPane.add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jButton1, null);
jPanel1.add(jButton2, null);
contentPane.add(jTextField1, BorderLayout.NORTH);

clip = null;
}

void jButton1_actionPerformed(ActionEvent e) {
try {
jButton1.setEnabled(false);
jButton2.setEnabled(true);
clip = java.applet.Applet.newAudioClip(new java.net.URL(this.jTextField1.getText()));
clip.play();
this.jLabel1.setText("Now Playing " + this.jTextField1.getText());
} catch (Exception err) {
err.printStackTrace();
}
}

void jButton2_actionPerformed(ActionEvent e) {
try {
jButton1.setEnabled(true);
jButton2.setEnabled(false);
clip.stop();
this.jLabel1.setText("Waiting .......");
} catch (Exception err) {
err.printStackTrace();
}
}
}

如果说这玩意也有难度,那么加油吧文件名 MainFrame.java
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
蓝色_灵魂
2011-04-29 · TA获得超过680个赞
知道小有建树答主
回答量:1127
采纳率:0%
帮助的人:555万
展开全部
没错啊
你的java文件的名字要是MainFrame.java才行,你看看自己的是不是
更多追问追答
追问
java.lang.NoSuchMethodError: main
Exception in thread "main"
我用Eclipse编译的
java.lang.NoSuchMethodError: main
Exception in thread "main"
我用Eclipse编译的
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
一杯热茶旦旦aD
2011-04-30
知道答主
回答量:14
采纳率:0%
帮助的人:0
展开全部
看看
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式