请各位java师哥师姐:"救命啊!救命啊!"急急急!
人气:
【字体:大 中 小】
发布时间:2008-11-20 12:38:32
>>>>>>>>提问我的这个java程序有错误请帮忙改正!谢谢!
错误提示如下:Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at sun.audio.AudioStream.<init>(Unknown Source)
at testsong.actionPerformed(testsong.java:53)
java.io.FileNotFoundException: wanqiu.mid (系统找不到指定的文件。)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
import sun.audio.*;
import java.io.*;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.event.*;
public class testsong extends JFrame implements ActionListener{
AudioStream as;
FileInputStream fileau;
JButton jButton1 = new JButton();
testsong(){
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
testsong t = new testsong();
t.setVisible(true);
t.setSize(200, 200);
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
jButton1.setText("jButton1");
jButton1.addActionListener(this);
this.getContentPane().add(jButton1);
jButton1.setBounds(175, 46, 151, 113);
}
public void actionPerformed(ActionEvent e) {
try {
fileau = new FileInputStream("wanqiu.mid");
} catch (FileNotFoundException ex) {
System.out.println(ex);
}
try {
as = new AudioStream(fileau);
AudioPlayer.player.start(as);
} catch (IOException ex1) {
System.out.println(ex1);
}
}
}
休闲 居 编辑
>>>>>>>>休闲养生网回答:public static void main(int k, int[][] a) {
int n = 1;
for (int i = 1; i <= k; i++)
n *= 2;
for (int i = 1; i <= n; i++)
a[1][i] = i;
int m = 1;
for (int s = 1; s <= k; s++) {
n /= 2;
for (int t = 1; t <= n; t++)
for (int i = m + 1; i < 2 * m; i++)
for (int j = m + 1; j <= 2 * m; j++) {
a[i][j + (t - 1) * m * 2] = a[i - m][j + (t - 1) * m
* 2 - m];
a[i][j + (t - 1) * m * 2 - m] = a[i - m][j + (t - 1)
* m * 2];
m *= 2;
}
}
System.out.println("你输入了数字" + k);
for (int i = 0; i <= n - 1; i++)
for (int j = 0; j <= n - 1; j++)
System.out.println(a[i][j]);
}
程序我给你改完了,把这个加你的类里就行了,我就那闷你的两个for 循环里怎以都没定义变量呀。
≡ 查看、发表评论 ≡