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

Akilah Jones
Akilah Jones
18,397 Points

Anyone using sublime text and java?

I'm currently using sublime text to compile my individual java files and then running from the terminal (mac os) and this works fine.

However, when I attempt to do the same with a java file that depends on another, such as Example.java and PezDispenser.java, I am not able to compile.

Although both files are in the same directory, PezDispenser is not recognized when I attempt to compile Example.java.

Example.java:8: error: cannot find symbol PezDispenser dispenser = new PezDispenser("Yoda");

Any ideas?

Harry James
Harry James
14,780 Points

Hey Akilah!

Have you managed to get this problem fixed yet? I've used a bit of Sublime Text but not for compiling code however, if you're still having issues, I'll try and look around to see what can be done :)

Akilah Jones
Akilah Jones
18,397 Points

Harry James

Unfortunately, I have not resolved the issue...

I've opted to just compile and run from terminal (for now), but would ultimately like to get sublime working. So thanks alot for offering to look around as well! It's greatly appreciated :-)

2 Answers

Hi Akilah,

If you haven't got this working yet, I managed to with the help of this thread.

I'm now able to compile multiple java files and run main in one step.

Cheers

Akilah Jones
Akilah Jones
18,397 Points

Thanks, Robert!

The following steps worked for me...

Created javacr.sh in home directory:

javac $1.java
java $1

Created New Build System in Sublime:

{
   "cmd": ["/Users/casa/javacr.sh", "$file_base_name" ],
   "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
   "working_dir": "${file_path}",
   "selector": "source.java"
}

Made script executable via terminal:

$ chmod 755 /Users/casa/javacr.sh

NOTE: The build failed until I made the last change per http://www.macinstruct.com/node/415

Brandon Zeck
Brandon Zeck
3,127 Points

Hi Akilah,<p>

I may have understood it wrong, but did you compile both PezDispenser.java and Example.java?</p><p>

If not, please compile PezDispenser.java first and then Example.java and try again.</p><p> Thanks.</p>

Akilah Jones
Akilah Jones
18,397 Points

Brandon Zeck

Yes, I did compile it and a class file was generated, it's just when I attempt to compile Example.java ...it doesn't recognize PezDispenser.

Thanks

Brandon Zeck
Brandon Zeck
3,127 Points

Akilah Jones,<p>

Do you have the java-repl installed?</p><p>

Else, it won't recognize the command and you may have to initialize the object from the program itself.</p><p>

You may find this post useful.</p><p>

Awaiting your reply.</p>

Akilah Jones
Akilah Jones
18,397 Points

Brandon Zeck

I do have java-repl installed and can load PezDispenser in the repl.

I actually (as a work-around) took the code from Example.java and pasted it into the java-repl just to test that the code was working as expected.

I also loaded Example and tried to call main from within the repl, i.e. Example.main(), but that was unsuccessful.

Thanks

Brandon Zeck
Brandon Zeck
3,127 Points

Akilah Jones,<p>

By copying it from Example.java, did you mean the one that was provided or the one you had in your system?</p><p>

If it was the one in your system, please post below, the code that did not work .</p><p>

Just want to make sure that the issue does not have something to do with the code.</p><p>

Awaiting your reply. Thanks.</p>

Akilah Jones
Akilah Jones
18,397 Points

Brandon Zeck

Sure...

Although, I'm pretty sure the issue has to do with Sublime Text (code works fine in the repl).

PezDispenser dispenser = new PezDispenser("Yoda");

The above snippet produces a "cannot find symbol" error

Thanks

Brandon Zeck
Brandon Zeck
3,127 Points

Akilah,<p>

Thanks for the response.</p><p>

Now, it is clear that it is not an issue with repl.</p><p>

Please look at the URLs below.</p><p>

Maybe you will find something useful.</p><p>

http://superuser.com/questions/652175/command-line-from-within-sublime-text</p><p> https://www.sublimetext.com/forum/viewtopic.php?f=3&t=4805</p><p> http://www.sublimetext.com/forum/viewtopic.php?f=3&t=1685</p><p>

I don't know if I would be able to help you out as I have not used Sublime Text</p><p>

Hope the links above help.</p><p>

Thanks.</p>

Akilah Jones
Akilah Jones
18,397 Points

Brandon Zeck

Thanks all the same, I appreciate your willingness to help :-)

Best Regards