0

任何人都可以帮助我提供以下错误报告(对于底部的代码):

Exception in thread "AWT-EventQueue-0" java.lang.VerifyError: Constructor must call super() or this() before return in method org.jfree.ui.RectangleInsets.<init>()V at offset 0
at org.jfree.chart.axis.Axis.<clinit>(Axis.java:153)
at org.jfree.chart.StandardChartTheme.<init>(StandardChartTheme.java:233)
at org.jfree.chart.StandardChartTheme.<init>(StandardChartTheme.java:319)
at org.jfree.chart.ChartFactory.<clinit>(ChartFactory.java:231)
at odesolver.ODESolver.createGraph(ODESolver.java:81)
at odesolver.ODESolver.<init>(ODESolver.java:35)
at odesolver.ODESolver$2.run(ODESolver.java:105)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
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)
BUILD SUCCESSFUL (total time: 2 seconds)  

这与以下 3 行代码有关:

ODESolver.java:81

JFreeChart chart = ChartFactory.createXYLineChart(

ODESolver.java:35

createGraph();

ODESolver.java:105

new ODESolver(); // Let the constructor do the job

整个程序:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package odesolver;

/**
 *
 * @author User
 */
import java.awt.*;       // Using AWT containers and components
import java.awt.event.*; // Using AWT events and listener interfaces
import javax.swing.*;    // Using Swing components and containers
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.ChartPanel;
import org.jfree.data.general.Series;

// A Swing GUI application inherits the top-level container javax.swing.JFrame
public class ODESolver extends JFrame {
   private JTextField tfInput, tfOutput;
   private int numberIn;   // input number
   private int sum = 0;    // accumulated sum, init to 0

   /** Constructor to setup the GUI */
   public ODESolver() {
      // Retrieve the content-pane of the top-level container JFrame
      // All operations done on the content-pane
      Container cp = getContentPane();
      cp.setLayout(new GridLayout(2, 2, 5, 5));

      createGraph();


      add(new JLabel("Enter an Integer: "));
      tfInput = new JTextField(10);
      add(tfInput);
      add(new JLabel("The Accumulated Sum is: "));
      tfOutput = new JTextField(10);
      tfOutput.setEditable(false);  // read-only
      add(tfOutput);

      // Allocate an anonymous instance of an anonymous inner class that
      //  implements ActionListener as ActionEvent listener
      tfInput.addActionListener(new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
            // Get the String entered into the input TextField, convert to int
            numberIn = Integer.parseInt(tfInput.getText());
            sum += numberIn;      // accumulate numbers entered into sum
            tfInput.setText("");  // clear input TextField
            tfOutput.setText(sum + ""); // display sum on the output TextField
         }
      });

      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  // Exit program if close-window button clicked
      setTitle("ODE Accumulator"); // "this" Frame sets title
      setSize(350, 120);  // "this" Frame sets initial size
      setVisible(true);   // "this" Frame shows


   }

   private JPanel createGraph() {

        JPanel panel = new JPanel();
        XYSeries series = new XYSeries("MyGraph");
        series.add(0, 1);
        series.add(1, 2);
        series.add(2, 5);
        series.add(7, 8);
        series.add(9, 10);


        XYSeriesCollection dataset = new XYSeriesCollection();
        dataset.addSeries(series);

        JFreeChart chart = ChartFactory.createXYLineChart(
                "XY Chart",
                "x-axis",
                "y-axis",
                dataset, 
                PlotOrientation.VERTICAL,
                true,
                true,
                false
                );
        ChartPanel chartPanel = new ChartPanel(chart);


        panel.add(chartPanel);

        return panel;
    }

   /** The entry main() method */
   public static void main(String[] args) {
      // Run the GUI construction in the Event-Dispatching thread for thread-safety
      SwingUtilities.invokeLater(new Runnable() {
         @Override
         public void run() {
            new ODESolver(); // Let the constructor do the job
         }
      });
   }
}

可能问题在于 ODESolver、src 和 lib 中的文件有错误,正如 netbeans 报告的那样(见下面的屏幕截图)。我不知道哪些文件应该有错误,因为没有一个文件上有感叹号,因为它们通常有错误。

网豆错误

4

3 回答 3

4

您似乎正在运行JFreeChart产生此错误的旧版本。升级到此处1.0.13找到的版本

于 2013-09-30T10:28:02.197 回答
0

通过将 jar 文件添加到类路径而不是包含它们的文件夹来解决问题

于 2013-10-03T15:18:38.230 回答
-1

各种构造函数都需要JFrame进行重要的初始化工作JFrame。因此,每JFrame一个被创建的都必须调用这些构造函数之一。但是因为 anODESolver也是 a JFrame,所以也适用于ODESolver对象。

幸运的是,Java 语言强制执行此操作。ODESolver如果没有调用其中一个JFrame构造函数,我们就无法创建, 。它强制执行它的方式是要求每个ODESolver构造函数都映射到一个JFrame构造函数。

当我们创建一个ODESolver时,其中一个ODESolver构造函数将被调用。但是该构造函数必须指定JFrame将调用哪个构造函数。它这样做的方式是执行以下操作之一。

  • 通过调用,明确指定JFrame使用哪个构造函数super(),带或不带一些参数;
  • 通过调用 调用另一个ODESolver构造函数,this()带或不带一些参数。

在任何一种情况下,对super()or的调用都this()必须是ODESolver构造函数的第一行。

于 2013-09-30T10:32:44.747 回答