【问题标题】:Error during compilation?编译时出错?
【发布时间】:2013-12-30 08:54:33
【问题描述】:

所以我一直在编写有关JPizza.java 的代码,我已经到了出现此错误的地步:

    JPizza.java:38: error: cannot find symbol
  music = getAudioClip(getCodeBase(),"katy_perry-roar.mid");
                       ^
  symbol:   method getCodeBase()
  location: class JPizza
  1 error

我一直在试图弄清楚为什么它会给我这些错误,但是 我在这里找不到主要问题?是不是因为我忘了定义 一个方法?对于 getCodeBase() 和 CodeBase() 我尝试将其定义为 CodeBase() = getCodeBase() 然后将错误转移到 getAudioClip

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class JPizza extends JFrame implements ItemListener, ActionListener
 {
  FlowLayout flow = new FlowLayout();
  JLabel companyName = new JLabel("PizzaPalooza");
  JComboBox<String> sizeBox = new JComboBox<String>();
  JLabel sizeList = new JLabel("Size List");
  JComboBox<String> toppingBox = new JComboBox<String>();
  JLabel toppingList = new JLabel("Topping List");
  JTextField totPrice = new JTextField(10);
  JLabel orderName = new JLabel("Name of Order");
  JTextField oName = new JTextField(15);
  JLabel listenLabel = new JLabel("Listen to our theme!");
  JButton playButton = new JButton("Play");
  JButton stopButton = new JButton("Stop");
  JLabel headLabel = new JLabel ();
  AudioClip music;
  int totalPrice = 0;
  int sizeNum, toppingNum;
  int sPrice, tPrice, sumPrice;
  int[] sizePrice = {0,7,9,11,14};
  int[] toppingPrice = {0,0,1,1,1,1};
  String output;
   public void init()
    {
     Container con = getContentPane();
     con.setLayout (new FlowLayout());
     con.add(headLabel);
     con.add(listenLabel);
     con.add(playButton);
     con.add(stopButton);
     playButton.addActionListener(this);
     stopButton.addActionListener(this);
     music = getAudioClip(getCodeBase(),"katy_perry-roar.mid");
    }

     public void actionPerformed(ActionEvent e)
     {
      Object source = e.getSource();
      if(source == playButton)
       music.loop();
      else
       music.stop();
     }

为此,但我不明白这是什么意思?

【问题讨论】:

  • 看上面的那行...
  • JLabel headLabel = new JLabel 行看起来有点修剪。这可能是问题所在。应该是JLabel headLabel = new JLabel("Some String");
  • 你在哪里定义的方法getCodeBase?或者它是内置在一个类中的(哪个?)?
  • @Flight 我假设因为你从另一个来源输入歌曲,你会使用 getCodeBase,它是在 java.awt.event.* 根据我的 Java 教授定义的。

标签: java compiler-errors jframe components identifier


【解决方案1】:

编译问题就在上面一行。您在

行中缺少 JLabel 构造函数括号和分号
  JLabel headLabel = new JLabel

应该是:

  JLabel headLabel = new JLabel();

【讨论】:

  • 您能帮我解决JPizza.java:38: error: cannot find symbol music = getAudioClip(getCodeBase(),"katy_perry-roar.mid"); ^ symbol: method getCodeBase() location: class JPizza 错误吗?我仍然不明白,对于 getCodeBase() 和 CodeBase() 我尝试将其定义为 CodeBase() = getCodeBase() 然后将错误转移到 getAudioClip
  • JFrame 不是Applet。
猜你喜欢
  • 1970-01-01
  • 2012-01-28
  • 2013-08-16
  • 2017-07-13
  • 2014-06-25
  • 2012-03-11
  • 2017-04-27
相关资源
最近更新 更多