Issue
While the same code working in NetBeans IDE It gives this error on eclipse ! I'm getting this error after running the code and giving the input
Exception in thread "main" java.lang.NoClassDefFoundError: net/sourceforge/jFuzzyLogic/FIS at pkt.Resturant.(Resturant.java:17) at pkt.Program.main(Program.java:15) Caused by: java.lang.ClassNotFoundException: net.sourceforge.jFuzzyLogic.FIS at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ... 2 more
Resturant.java file
package pkt;
import java.io.File;
import java.net.URISyntaxException;
import net.sourceforge.jFuzzyLogic.FIS;
public class Resturant {
private FIS fis;
private double servis;
private double yemek;
public Resturant(double servis, double yemek) throws URISyntaxException {
this.servis = servis;
this.yemek = yemek;
File dosya = new File(getClass().getResource("Model.fcl").toURI());
fis = FIS.load(dosya.getPath(), true);
fis.setVariable("servis", servis);
fis.setVariable("yemek", yemek);
fis.evaluate();
}
public Resturant() throws URISyntaxException {
File dosya = new File(getClass().getResource("Model.fcl").toURI());
fis = FIS.load(dosya.getPath(), true);
}
public FIS getModel() {
return fis;
}
@Override
public String toString() {
String cikti = "servis: " + servis + "\nYemek: " + yemek + "\nTur: " + fis.getVariable("tur").getValue();
return cikti;
}
}
Program.java file
package pkt;
import java.net.URISyntaxException;
import java.util.Scanner;
import net.sourceforge.jFuzzyLogic.plot.JFuzzyChart;
public class Program {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Servis (0-9): ");
double servis = in.nextDouble();
System.out.print("Yemek (0-9): ");
double yemek = in.nextDouble();
try {
Resturant r = new Resturant(servis,yemek);
System.out.print(r);
} catch(URISyntaxException e) {
e.printStackTrace();
}
}
}
And the JFuzzyLogic file Model.fcl
FUNCTION_BLOCK model
VAR_INPUT
servis : REAL;
yemek : REAL;
END_VAR
VAR_OUTPUT
tur : REAL;
END_VAR
FUZZIFY servis
TERM kotu := (0,1)(4,0);
TERM iyi := (1,0)(4,1)(6,1)(9,0);
TERM mukemmel := (6,0)(9,1);
END_FUZZIFY
FUZZIFY yemek
TERM kotu := (0,1)(3,1)(6,0);
TERM lezzetli := (4,0)(9,1);
END_FUZZIFY
DEFUZZIFY tur
TERM ucuz := (0,1)(20,1)(50,0);
TERM orta := (40,0)(60,1)(80,0);
TERM iyi := (70,0)(85,1)(100,0);
METHOD : COG;
DEFAULT := 0;
END_DEFUZZIFY
RULEBLOCK kuralblock1
AND : MIN;
ACT : MIN;
ACCU : MAX;
RULE 1 : IF servis IS kotu OR yemek IS kotu THEN tur IS ucuz;
RULE 2 : IF servis IS iyi THEN tur IS orta;
RULE 3 : IF servis IS mukemmel AND yemek IS lezzetli THEN tur IS iyi;
END_RULEBLOCK
END_FUNCTION_BLOCK
Solution
I figured out what the problem is, It's the way of adding the FazzyLogic library! Instead of adding it to the Classpath I added it to the Modulepath! I've no experience with java neither eclipse IDE.
Answered By - Nermin Kaya