0

I have been updating my development environment to Eclipse Neon and introducing m2e to manage project dependencies. in one project the original (very old) versions of JFreeChart were not available on maven so I have put in the latest versions of JFreeChart and JCommon.

I now have one compile error, described below:

The type org.jfree.data.general.Series cannot be resolved.
It is indirectly referenced from required .class files.

I have found a number of questions and answers about this, but they seem to relate to the absence of JCommon. I have JCommon in my dependencies, and I have checked the specific class that is referred to is actually in the jfreechart.jar file with 7-zip. Below is the code fragment with the error, which occurs on the last else statement results.add(…).

public XYDataset getMetricHistogramData(Timestamp t1, Timestamp t2){
    int index1=-1;
    Timestamp startTime,endTime;
    TimePeriodValues results = new TimePeriodValues(this.type.name());
    final TimePeriodValuesCollection results1 = new TimePeriodValuesCollection();

    if (t1.before(earliest)||t1.after(latest)||(readings.size()<=1)) return null; // won't find a value for the timestamp t1
    if (t2.before(earliest)||t2.after(latest)) return null; // won't find a value for the timestamp t2

    for(int i = 0;i<readings.size();i++){
        if (readings.get(i).timestamp().equals(t1)){
            index1=i;
            break;
        }
        if (readings.get(i).timestamp().after(t1)){
            index1=i-1;
            break;
        }       
    }
    // index1 now contains the index of the starting timestamp
    for (int i=index1; i<(readings.size()-1); i++){
        startTime = readings.get(i).timestamp();
        if(startTime.after(t2)) break;
        //endTime = new Timestamp(Math.abs(readings.get(i+1).timestamp().getTime()-Timestamped.SECOND_IN_MS));
        endTime = readings.get(i+1).timestamp();
        if (endTime.before(startTime))
            SmartPower.getMain().getFrame().displayLog("Bad Timestamps "+startTime + " - " + endTime+"\n\r");
        else results.add(new SimpleTimePeriod(startTime, endTime), readings.get(i).value());
    }
    results1.addSeries(results);
    return results1;
}

This is my pom.xml file

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>SmartPower</groupId>
  <artifactId>SmartPower</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <!-- https://mvnrepository.com/artifact/org.eclipse.persistence/javax.persistence -->
    <dependency>
      <groupId>org.eclipse.persistence</groupId>
      <artifactId>javax.persistence</artifactId>
      <version>2.1.1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.jfree/jfreechart -->
    <dependency>
      <groupId>org.jfree</groupId>
      <artifactId>jfreechart</artifactId>
      <version>1.0.19</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.jfree/jcommon -->
    <dependency>
      <groupId>org.jfree</groupId>
      <artifactId>jcommon</artifactId>
    <version>1.0.23</version> 
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.jgoodies/forms -->
    <dependency>
      <groupId>com.jgoodies</groupId>
      <artifactId>forms</artifactId>
      <version>1.2.1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.derby/derby -->
    <dependency>
      <groupId>org.apache.derby</groupId>
      <artifactId>derby</artifactId>
      <version>10.12.1.1</version>
</dependency>

  </dependencies>
</project>

Neon was a clean install about a week ago on windows 10.

Any pointers would be appreciated.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
gjwo
  • 175
  • 13

1 Answers1

1

I'm not sure where things are going awry. The class org.jfree.data.general.Series is indeed included in jfreechart-1.0.19.jar. You might try running from the command line with the -verbose option, as suggested here, to check for stray JARs. Using the 1.0.19 release,

$ java -verbose -cp .:lib/jfreechart-1.0.19.jar:lib/jcommon-1.0.23.jar Test
…
[Loaded org.jfree.data.general.SeriesDataset from file:lib/jfreechart-1.0.19.jar]
[Loaded org.jfree.data.xy.XYDataset from file:lib/jfreechart-1.0.19.jar]
…

Using the versions cited, the following simplified example produces the following chart without error:

image

import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.JFrame;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.data.time.Day;
import org.jfree.data.time.TimePeriodValues;
import org.jfree.data.time.TimePeriodValuesCollection;
import org.jfree.data.xy.XYDataset;

/**
 * @see https://stackoverflow.com/a/38725689/230513
 */
public class Test {

    private void display() {
        JFrame f = new JFrame("Test");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(new ChartPanel(ChartFactory.createTimeSeriesChart(
            "Title", "Domain", "Range", createDataset())) {
            @Override
            public Dimension getPreferredSize() {
                return new Dimension(640, 480);
            }
        });
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    }

    private XYDataset createDataset() {
        TimePeriodValues results = new TimePeriodValues("Data");
        results.add(new Day(1, 8, 2016), 1);
        results.add(new Day(2, 8, 2016), 2);
        return new TimePeriodValuesCollection(results);
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Test()::display);
    }
}
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • If this is not helpful, please edit your question to include a [mcve] that exhibits the problem you describe. – trashgod Aug 02 '16 at 16:18
  • This points to the problem being with the Eclipse environment, rather than with the jar files. I think I have provided all the detail on that in the original question. I will try you code fragment in my environment. – gjwo Aug 04 '16 at 14:08
  • I added a test package into my structure org.ladbury.testPkg and then created a new test class in the package using your code above. I am getting an error on the enclosing package statement of "The type org.jfree.data.DomainInfo cannot be resolved. It is indirectly referenced from required .class files" + assorted other errors. This class is also present in the jfreechar.jar file. I notice your jar files include "-fx" after the version, mine doesn't is this significant? – gjwo Aug 04 '16 at 14:40
  • Ah, the wildcard found the `-fx` JAR first; I don't see any difference when I use the release JAR explicitly, cited above; I suspect your maven artifact; compiling by hand might help decide. Do you need to [`clean`](http://stackoverflow.com/q/4367665/230513)? – trashgod Aug 04 '16 at 15:54