• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Starting out with Java and a small problem...

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 73263
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 73263
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
lowercase baba
Posts: 12992
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Marshal
Posts: 73263
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 73263
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
. . . but the setDefaultCloseOperation method only works if I change all the Components to their Swing counterparts.
 
Campbell Ritchie
Marshal
Posts: 73263
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I got to run, but it doesn't do anything:-
 
Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic