Java: Unresolved Compilation Problem

How to fix Java error Unresolved compilation problem in Eclipse IDE?

beside the fact you didn't post your whole code, I was able to run the piece of code you put over there:

Sample Image

So or your issue is below the code you posted, or it is just a compilation problem in your IDE

I would recommend to you manually refresh your project and force clean it using the menu Project > Clean in Eclipse. I will force your app to recompile.

Unresolved compilation problem while executing Java in VS Code

It looks like you’re having a file with a name test1.java, but the java compiler requires that the file name matches the name of the public class inside.

Try either

  • renaming the file to app.java
  • renaming the class apptest1, but then you’ll have to rename existing test1 to something else
  • make the app not public (and you will still be able to run it)

(I’m not sure why VS Code doesn’t report this problem properly.)

Why do I get this error in Java? Exception in thread main java.lang.Error: Unresolved compilation problems

A class can be instantiated via the constructor . so you need to make linearequationproblem as a constructor like below.

import java.util.Scanner;
public class lineequation {
private double a;
private double b;
private double c;
private double d;
private double e;
private double f;

public lineequation(double a, double b, double c, double d, double e, double f) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.e = e;
this.f = f;
}
public double getA(){
return this.a;
}
public double getB(){
return this.b;
}
public double getC(){
return this.c;
}
public double getD(){
return this.d;
}
public double getE(){
return this.e;
}
public double getF(){
return this.f;
}
public boolean isSolvable(){
if(this.a * this.d - this.b * this.c == 0) return false;
return true;
}
public double getX(){
if(isSolvable()) return ((e * d) - (b * f))/((a * d) - (b * c));
return -1;
}
public double getY(){
if(isSolvable()) return ((a * f) - (e * c))/((a * d) - (b * c));
return -1;
}

public static void main(String []args){
Scanner input = new Scanner(System.in);
System.out.println("Enter a, b, c, d, e, f one at a time starting with a. ");
double []in = new double[6];
for(int l = 0; l < 6; l++){
in[l] = input.nextDouble();
}
lineequation test = new lineequation(in[0], in[1], in[2], in[3], in[4], in[5]);
while(true){

System.out.println("Type in a-f to show what you have entered OR 'progress' to progress with the script.");
String t = input.next();

if(t.equals("progress")) break;
else if(t.equals("a")) System.out.println(test.getA());
else if(t.equals("b")) System.out.println(test.getB());
else if(t.equals("c")) System.out.println(test.getC());
else if(t.equals("d")) System.out.println(test.getD());
else if(t.equals("e")) System.out.println(test.getE());
else if(t.equals("f")) System.out.println(test.getF());
else System.out.println("Error, please enter a valid input. ");
}

while(true){
System.out.println("To show the output of either x or y, enter 'x' or 'y' or type 'quit' to end the script.");
String output = input.next();
if(output.equals("quit")) break;

try{
if(!test.isSolvable()) throw new Exception();
if(output.equals("x")) System.out.println(test.getX());
else if(output.equals("y")) System.out.println(test.getY());
else System.out.println("Error, please enter a valid input. ");
}catch (Exception e){
System.out.println("The equation has no solution.");
break;
}
}
}
}


Related Topics



Leave a reply



Submit