• Post Reply Bookmark Topic Watch Topic
  • New Topic

Beginners question on running programs  RSS feed

 
Keith Suddick
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not new to programming but am new to Java so I've been following the Stanford CS106A programming course and have just done the "Breakout" assignment - to write a simple Breakout game. I'm using Eclipse on a Mac so I have a class file called "Breakout.java" and like all the classes I've seen in CS106A so far it contains a "run" method that actually plays the game. So I have...


This "runs" fine within Eclipse, but I wanted to create a standalone JAR file that I could try running on another machine. After reading some posts on exporting from Eclipse I tried this and got an error message that a main method could not be found. I looked this up and it seemed that I needed a class with a main method - I initially tried adding one to the Breakout class but that generated an error about calling the non-static method "run" and I assumed I needed something to create an instance of my Breakout class. Now, I've added another class called "BreakoutApp" which contains...


Now, I don't get any errors when I export to the JAR file but when I "run" this class in Eclipse, I get a Java program running called "BreakoutApp" but it doesn't play the game, it seems to do nothing. If I double-click the exported JAR file, I get an error that it couldn't be run and to consult the console (which I can't seem to find on this Mac but that's another issue!).

I've tried quite a few searches, but can't find anything that explains where I am going wrong, so I would be grateful for any advice or suggestions.

Many thanks,

Suds
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your Breakout class extends the GraphicsProgram class and it's probably something in the GraphicsProgram class that calls the run method. It probably also does some initialisation which is needed before any graphics are displayed.
I presume the GraphicsProgram class was provided by your professor (it's not part of the standard API), so you may need to look at the documentation for this class (or your class notes) to see how to use it properly.
Alternatively you could look at the Run configuration in Eclipse and see what command line it is set up to use.

 
Keith Suddick
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stuart, thank you for your reply. I hadn't realised the GraphicsProgram class was not "standard" so I did some checking. It's part of the ACM Java Task Force package and this was provided as part of the start-up materials for the Stanford course. I've done some reading on the JTF's website and it discusses the inclusion or omission of a main method in classes using the acm package and adding this...


to my Breakout class seems to have solved the problem - it still runs within Eclipse but the standalone .JAR file now also plays the game - although it doesn't work when I transfer the files to my PC and try it there, but that's another problem!

Thanks again for your help in getting me looking in the right place.


Suds
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!