Click here to Skip to main content
15,911,132 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to make a really simple program with two constructors. I keep getting this error
Exception in thread "main" java.lang.NoSuchMethodError: Tuition.getResidency()Ljava/lang/String;
	at UnitTest.main(UnitTest.java:14)

and I can't seem to figure out what the problem is. Here is the code.
public class Tuition {
  private String name;
  private String studentnumber;
  private String residency;
  private String credithours;

  public Tuition(String argName, String argStudentNumber, String argResidency, String argCreditHours){
    size=argName;
    name=argStudentNumber;
    residency=argResidency;
    credithours=argCreditHours;
  }

  public Tuition(String argName, String argStudentNumber, String argCreditHours){
    size=argName;
    name=argStudentNumber;
    residency=argResidency;
    credithours="IC";
  }

    public void setName(String arg){
  		name=arg;
  	}
  	public void setStudentNumber(String arg){
  		studentnumber=arg;
  	}

    public void setResidency(String arg){
      residency=arg;
    }

  	public void setCreditHours(String arg){
  		credithours=arg;
  	}

  	public String getName(){
  		return name;
  	}

  	public String getStudentNumber(){
  		return studentnumber;
  	}

    public String getResidency(){
      return residency;
    }

  	public String getCreditHours(){
  		return credithours;
  	}



public class UnitTest{
 public static void main(String[] args) {


  Tuition s1=new Tuition("435353", "Geralt Rivia", "IC", "3");
  System.out.println("Student" + s1.getStudentNumber());
  System.out.println(s1.getName());
  System.out.println("takes " + s1.getCreditHours ());
  System.out.println("credit hours. Residency = " + s1.getResidency());
  System.out.println(", tution = $" + s1.calculateTuitionIC());
}
}


What I have tried:

looking for solutions for this error. I haven't found much.
Posted
Updated 6-May-20 20:05pm

Have you debugged line-by-line?
It might be a simple copy-paste issue, but you're missing a final closing bracket for the Tuition class. Also, residency would not be set in this method, because the arg isn't passed.
Java
public Tuition(String argName, String argStudentNumber, String argCreditHours){
  size=argName;
  name=argStudentNumber;
  residency=argResidency;
  credithours="IC";
}
 
Share this answer
 
This error occurs when No variable declaration or variable is outside of the scope you are referencing it in.
In your problem, the following Tuition function missed out argResidency parameter :

Java
public Tuition(String argName, String argStudentNumber, String argCreditHours){
    size=argName;
    name=argStudentNumber;
    residency=argResidency;
    credithours="IC";
  }

So your solution code is the following :
Java
public Tuition(String argName, String argStudentNumber, String argCreditHours, String argResidency){
    size=argName;
    name=argStudentNumber;
    residency=argResidency;
    credithours="IC";
  }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900