【问题标题】:How to resolve the following errors (about jmathpolt)?如何解决以下错误(关于 jmathpolt)?
【发布时间】:2023-02-09 22:43:29
【问题描述】:

想使用jmathplot等包来绘制函数图像,但是添加相关包后,抛出一个无法解决的问题。

import javax.swing.*;
import org.math.plot.*;
public class Example {
    public static void main(String[] args) {
        // define your data
        double[] x = { 1, 2, 3, 4, 5, 6 };
        double[] y = { 45, 89, 6, 32, 63, 12 };
        // create your PlotPanel (you can use it as a JPanel)
        Plot2DPanel plot = new Plot2DPanel();
        // define the legend position
        plot.addLegend("SOUTH");
        // add a line plot to the PlotPanel
        plot.addLinePlot("my plot", x, y);
        // put the PlotPanel in a JFrame like a JPanel
        JFrame frame = new JFrame("a plot panel");
        frame.setSize(600, 600);
        frame.setContentPane(plot);
        frame.setVisible(true);
    }
}

相关jar文件在GitHub上下载。

【问题讨论】:

标签: java jmathplot


【解决方案1】:

您显然正在使用 JMathPlot 库的 1.0 版本(来自 GitHub 或 Maven Central)。该版本的 JAR 缺少包含库标准图标的 /org/math/plot/icons/ 文件夹。当 Swing 尝试从类路径加载图标时,这会导致 NPE。

解决方案是使用 JMathPlot 1.0.1 ...它缺少图标。您可以通过此 URL 从 Maven Central 获取它:

或者,如果您从源代码构建库 JAR,您应该得到一个可用的 JAR。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-04
    • 1970-01-01
    • 1970-01-01
    • 2021-03-14
    • 2021-09-09
    • 2021-09-02
    • 1970-01-01
    相关资源
    最近更新 更多