1

I am trying to use the SimpleRegression class (link). I first imported the .jar file as external jar into my project and I can see it is imported. When I try :

import org.apache.commons.math3.stat.regression.*; 

I have no error message, so the jar file is correctly imported,

but when I import specifically the class I need:

import org.apache.commons.math3.stat.regression.SimpleRegression;

I get the message that SimpleRegression cannot be resolved.

Can somebody tell me what I did wrong? I downloaded the package from here .

thanks for your help

Vishal Panara
  • 746
  • 4
  • 19
Lori
  • 11
  • 1
  • 4
  • Try rebuilding your project (clean - build) – PKey Aug 16 '16 at 07:04
  • Could be a typo, invisible character or damaged source code file. Did that happens when you create a new source file ? What is the exactly compiler message ? – PeterMmm Aug 16 '16 at 07:05
  • What is the *exact* error message? – Erwin Bolwidt Aug 16 '16 at 07:13
  • @Erwin Bolwidt and PeterMmm The exact error message is "The import org.apache.commons.math3.stat.regression.SimpleRegression cannot be resolved". – Lori Aug 16 '16 at 07:20
  • @ Plirkee, Unfortunately the clean-build did not solve the problem. – Lori Aug 16 '16 at 07:22
  • @PeterMmm I have had that problem since the very first time I tried to import my class. I did try to copy paste it from some websites and to type it myself in order to avoid errors, but I have the same error with all the methods... – Lori Aug 16 '16 at 07:25
  • @Lori 2 things I would try: (1) open the JAR and see if the class file is really in there (2) leave the wildcard import and use the class in code, any error given ? – PeterMmm Aug 16 '16 at 07:39
  • @PeterMmmm (1) I checked into the jar file itself, there I can find the SimpleRegression.java document. I do however not see it in the Referenced library, I don t see until classes there, the last thing I do see is the "org.apache.commons.math3.stat.regression" step. But maybe this is normal? (2) when using the wildcard import I get the following error: Multiple markers at this line - SimpleRegression cannot be resolved to a type - SimpleRegression cannot be resolved to a type - Illegal modifier for parameter regression; only final is permitted – Lori Aug 16 '16 at 07:49
  • Thank you @PeterMmm I just realized the import had not worked properly (and did not allow me to see the classes of the library). I will search for another JAR file and the problem should be solved. Thanks for all your help and suggestions. – Lori Aug 16 '16 at 08:05
  • @Lori: seems like you picked the _sources_ jar file. The right one should contain `SimpleRegression.class` not `SimpleRegression.jav‌​a` – Trinimon Aug 16 '16 at 08:31
  • @Trinimon yes indeed I did take the _source_ jar file, now I m trying to get the right _bin_ file but I am having a hard time finding the kind of file I need to download from [here](http://commons.apache.org/proper/commons-math/download_math.cgi) and what to do with it after. (I did try the "commons-math3-3.6.1-bin.zip" file, but when I tried to import in as external JAR library, I did not get the classes, so I must have done something wrong). – Lori Aug 16 '16 at 09:03
  • OK found it, seems like the jar file is now IN the zip file as described [in a comment here](http://stackoverflow.com/a/2331818/6720531) thank you all – Lori Aug 16 '16 at 09:09
  • @Lori: just download http://ftp.halifax.rwth-aachen.de/apache//commons/math/binaries/commons-math3-3.6.1-bin.zip, unpack its contents and you will find the _commons-math3-3.6.1.jar_ library easily. p.s. ok, you found it already :D – Trinimon Aug 16 '16 at 09:09

1 Answers1

0

If your are using NetBeans the way to add a library to your class path is to go to File-Open Project-Select Your Project Name-Right Click on Libraries-Click Add Jar/Folder and then select your jar file. Then you must wait for it to do it's background scan before your run with the new imports. It is possible that an error occurred when you imported the jar into your project so try removing the jar now, then follow the steps above to add it to your class path. If it still doesn't work after that the jar file may be corrupted.

J. Alfonso
  • 21
  • 2
  • I am using Eclipse. I went with Build Path>Configure Build Path>Library>Add External JARs. I have restarted Eclipse this morning and it was still not working. – Lori Aug 16 '16 at 07:18
  • Try using the Project-Clean option and if the clean option doesn't work, make sure that your jre is compatible with the jre that the jar file requires. – J. Alfonso Aug 16 '16 at 21:49
  • @Lori, I got the same question like yours and it works for me after adding JARs. – FannieY Feb 28 '20 at 16:30