File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Starting out with Java and a small problem... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Starting out with Java and a small problem..." Watch "Starting out with Java and a small problem..." New topic
Author

Starting out with Java and a small problem...

Kai Windle
Greenhorn

Joined: Apr 11, 2007
Posts: 2
Hi

After much ummm and arr I taken the plung to learn another language after VB (don't laugh we have to start some where ), and found that I like the look of JAVA also when I found out "Write once run any where" I thought it was too good not to learn, so any way back to my problem I bout "Head First Java" and in chapter 1 page 3 you have a small expample of an application which goes some thing like this..

How ever when i come to run this like so "java Party" i get ..


and don't know why as you may have guessed im using mac os x tiger 10.4.9. Can any one help shead some light why it wont run and why i get that message.

Thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40061
    
  28
Welcome to the Ranch. Good idea to try learning Java.

A very common problem. At least you have Java set up and running correctly to get that error at all.

I presume that they have provided the whole application in HFJ? Somewhere in it you will find a method with the heading:-The Java virtual machine looks for this method heading (the main method) and when it finds it, starts implementation there.
1: Check that you have a main method in the example given, and also in what you have written out.
2: Look for another example (maybe on the next page) which might look like this:-3: Check that your spelling of "public static void main(String[] args)" is correct; there are only very slight variations permissible.

If that doesn't work, come back and ask again.
[ April 11, 2007: Message edited by: Campbell Ritchie ]
Kai Windle
Greenhorn

Joined: Apr 11, 2007
Posts: 2
Hi Campbell,

Thanks for the reply, I've checked and double checked that theres no main() method in this example if i could scan this exmple in i would then provide you with a link to it but i cannot , the example called MyFirstApp.java does how ever have a main() method , I've even tryed to enter a main() method into that example and still it refueses to run.., then after a quick thought here is the new code which seems to work though mac os x wont show the window lol and i only know its working because of the way mac os x apps work menu wise .

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40061
    
  28
Have you been through the book looking for related examples? There may be an example on another page which provides the requisite main method.
Difficult to tell what you are doing in the example which will run and won't compile, but it is generally a bad idea to put all that amount of code into the main method.

Find the first example in the Java Tutorial Swing (GUI) "trail." Copy its main method, and change it to this:-Look through the Party class for code which looks like this:-If you can't find it, put that code at the end of the buildInvite() method and see what happens. If you have difficulty I might have spelt the methods wrongly; use this web page to check on the spelling.

I still think they have provided a class with a main method to set off this application and you haven't found it yet. Go through the whole of chapter 1 until you find it. I don't have a copy of HFJ; anybody with a copy know whether there is another page number we ought to recommend?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11499
    
  16

I think that this is not really a working example, but just a snapshot of part of one. It is not meant to be run, as it won't work.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40061
    
  28
From Fred Rosenberger:
It is not meant to be run, as it won't work.
Like the late Magnus Magnussen, "I've started, so I'll finish." I got it to run. Not that is did anything interesting.
[ April 11, 2007: Message edited by: Campbell Ritchie ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40061
    
  28
. . . but the setDefaultCloseOperation method only works if I change all the Components to their Swing counterparts.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40061
    
  28
This is what I got to run, but it doesn't do anything:-
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Starting out with Java and a small problem...