Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Objects (Retired) Harnessing the Power of Objects Helper Methods and Conditionals

Error??? java> MethodConstant dispenser = new MethodConstant("Yoda");

treehouse:~/workspace$ java-repl
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
Welcome to JavaREPL version 303 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_65)
Type expression to evaluate, :help for more options or press tab to auto-complete.
java> :load MethodConstant.java
Loaded source file from MethodConstant.java
java> MethodConstant dispenser = new MethodConstant("Yoda");
ERROR: cannot find symbol
symbol: class MethodConstant
location: interface Evaluation
MethodConstant method$3f06zr157gtbhdxmaly9();

why do I get this error whilst using repl? I have checked for syntax errors and found nothing wrong. Also my code runs fine. Here it is below

public class om {

  public static void main(String[] args) {
    System.out.println("We are a making a new Pez Dispencer.");
    MethodConstant dispenser = new MethodConstant("Yoda");
    System.out.printf("The dispencer character is %s\n", dispenser.getCharacterName());

  }
}

& the other file is

public class MethodConstant {

  public static final int MAX_PES = 12;
  private String mCharacterName;   
  private int mPezCount;

  public MethodConstant(String characterName) {
    mCharacterName = characterName;
    mPezCount = 0;
  }

  public boolean isEmpty() {
    return mPezCount == 0
  }
  public void load()  { 
    mPezCount = MAX_PES;
  }
  public String getCharacterName() {
    return mCharacterName;
  }
}

[MOD: edited code block - srh]

1 Answer

Alexander Nikiforov
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 Points

Before you go to REPL, try to compile your class first to see the compiler errors.

So if you type:

javac MethodConstant.java

Compiler will tell you where the error and how to fix it, very straightforward error.

So make sure you do this every time before you go to repl...

Yes I have done that each time and the compiler shows no errors. However if i type: java MethodConstant then I get the message: Error: Main method not found in class MethodConstant, please define the main method as: public static void main(String[] args) or a JavaFX application class must exten javafx.application.Application.

At this stage I don't know what this means. When I run javac om.java && java om, then everything works fine

Alexander Nikiforov
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 Points

That is very strange, because i do get the error

I was not lazy and even made a video how i do it, And put in on YouTube. You can take a look:

https://www.youtube.com/watch?v=1W45vKGIcFM

But anyway error is quite simple. You forgot the column. That is exactly what compiler says:

Picked up JAVA_TOOL_OPTIONS: -Xmx128m                               
Picked up _JAVA_OPTIONS: -Xmx128m                                   
MethodConstant.java:13: error: ';' expected                         
    return mPezCount == 0                                           
                         ^                                          
1 error                

So add the necessary semi-colon.