Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[Mac] Can't run class files through terminal but NetBeans works fine

 
Cristian Malmros
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
edit: Solved it myself. When saving files in Coda I should not save it like: test.java but just test. If I add the .java part it messes things up.

I am running Mac OS X Leopard and I'm using Coda to write my Java with. Since Coda doesn't have its own compiler I need to use the Terminal to compile and run my java files.

I wrote a simple thing that had a jframe with a button and a text field where you could input a few characters. The button didn't do anything and it is just very basic. I used the terminal to go to the folder where the file was and I wrote:



It seemed to work fine and I got no errors. When I tried to run it the little app icon in the dock appeared but then it disappeared right after. It just closed itself. I took the same code and put it into NetBeans and compiled and ran it from there and the thing showed up and it worked right away.

I really want to keep using Coda but I don't want to have to move my code into NetBeans all the time to compile and run it. Does anyone have a clue why it crashes/closes itself right away (the jframe never even shows up) when using the Terminal?

 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are supposed to write the name of the class with the main method, minus extension at the command line.
javac MyClass.java
java MyClass
If you have an application which appears and vanishes, there may be another sort of error. Are you getting a stack trace from an Exception or anything like that? Does the prompt reappear at the terminal window?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic