Help! Language Families Project

So I’m currently working on the Language Families java project (https://www.codecademy.com/courses/learn-java/projects/java-language-families) and when I try to run the code I get the error: “could not find or load main class Language caused by: java.lang.ClassNotFoundException: La…”

My code is:
public class Language {
protected String name;
protected int numSpeakers;
protected String regionsSpoken;
protected String wordOrder;

public Language(String langName, int speakers, String regions, String wdOrder){
this.name = langName;
this.numSpeakers = speakers;
this.regionsSpoken = regions;
this.wordOrder = wdOrder;
}

public void getInfo(){
System.out.println(langName + " is spoken by " + speakers + " people mainly in " + regions + ". The language follows the word order: " + wdOrder);
}
public static void main(String args) {
Language french = new Language(“French”, 80000000, “France, Canada and parts of the Caribbean”, “subject-verb-object”);
french.getinfo();
}
}

I would massively appreciate your help on this; it’s taking all my self restraint not to chuck my laptop out the window! Thanks!


Is the name of the class the same as the name of the file? (I can’t access that project)

That error is commonly caused by a mismatch between the name of your file (language.java, possibly?) and the name of your class (Language). As a first step, and hopefully a last one, ensure they match exactly.

When running your code following this guideline, I did not encounter that error.


As an aside, both your getInfo() and main() methods have errors in them: In getInfo() you make reference to the parameters passed to the Language() constructor. These variables do not exist in getInfo(). Instead, you’ll need to use the this keyword to reference the instance variables. Your function, fixed:

public void getInfo(){
    System.out.println(this.name + " is spoken by " + this.numSpeakers + " people mainly in " + this.regionsSpoken + ". The language follows the word order: " + this.wordOrder);
  }

In the main() method, you call french.getinfo(). Your function is named Language.getInfo() (with a capital I). Update your call to french.getInfo() to solve this problem.

1 Like