0
我試圖將JAR添加到NetBeans項目。將JAR添加到NetBeans項目(答案似乎不起作用)
我右鍵單擊庫,然後選擇添加JAR /文件夾並選擇JAR,但導入無法識別。
我知道導入是在那些JAR中,因爲它在Eclipse中工作。
例如,import語句
import org.jfree.chart.ChartFactory;
在紅色下劃線,並有此錯誤消息:
cannot find symbol
symbol: class ChartFactory
location: package org.jfree.chart
----
(Alt-Enter shows hints)
編輯:
我使用NetBeans 7.3.1已經和JDK 7 u 25(64位)。
包含的項目中,我得到了上述誤差是(希望)可以在這裏找到一個ZIP文件:https://app.promobucket.com/the-church/spine-panel/a-sample-collection-1/splinepanel
的代碼是在這裏:
package splinepanel;
import java.awt.*; // Using AWT containers and components
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;
/**
*
* @author User
*/
public class SplinePanel{
public JPanel createContentPane(){
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
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);
//chart.getXYPlot().setRenderer(new XYSplineRenderer());
panel.add(chartPanel);
panel.setOpaque(true);
return panel;
}
private static void createAndShowGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("[=] There's a JPanel in here! [=]");
//Create and set up the content pane.
SplinePanel demo = new SplinePanel();
frame.setContentPane(demo.createContentPane());
// The other bits and pieces that make our program a bit more stable.
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1300, 650);
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
編輯2:
該項目現在可在這裏:
https://github.com/bluesh34/SplinePanel/
感謝您的努力。我已經有一個lib文件夾:我想我已經嘗試過這種方法了。無論如何,我將jar複製到lib中,並從項目屬性中刪除了jar。我去項目屬性重新添加罐,但他們已被自動添加(但路徑仍然是相同的,你說的是錯誤的,因爲他們是絕對的)。無論如何,恐怕錯誤仍然存在(包括我提出的問題)。 –
另外我不知道如何,但我忘記解決項目問題的地方,找不到它。你能告訴我它在哪裏嗎? –