• Post Reply Bookmark Topic Watch Topic
  • New Topic

cant understand why this wouldnt compile in eclipse?  RSS feed

 
sean slater
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import acm.graphics.*;
import acm.program.*;
public class helloworld extends Graphics.Program{
public void run(){
add {new Glabel {"hello,world ",100,75}};
}}

I am a newbie and I am self learning.Please help.

the eclipse says there isnt a main....
 
James E Baker
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sean slater wrote:

the eclipse says there isnt a main....


When you run something in Java, it looks for the "main" method as a starting point. If you class doesn't have one, it can't be executed unless it's being called by some other code somewhere.

Add this into your class....
 
bhanu chowdary
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sean slater wrote:the eclipse says there isnt a main....

This is not a compilation problem, you can see a class file generated if you navigate to your project folder. You will see this kind of error when you try to run a piece of code which do not have a main method...
 
sean slater
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi thanks for the fast reply
i have changed the code,but is this what you mean?


import acm.graphics.*;
import acm.program.*;
public class helloworld extends Graphics.Program{
public static void main (){
add {new Glabel {"helloworld",100,75}};
}}

but i tried this but still its asking for main.
I was listening to stanford lectures CS 106A and video no 4.
http://www.youtube.com/watch?v=nWheM30THaY&feature=relmfu
I dont have any other books right now, honestly i kinda feel i 'm missing something pretty obvious.
Do you mind recommending a source of learning, either book or a website where i can learn considering i m a beginner to programming.
thanks in advance.
 
bhanu chowdary
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you missed the parameters to the main method...It should be something like



You can start with Head First Java.
 
sean slater
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bhanu chowdary wrote:
sean slater wrote:the eclipse says there isnt a main....

This is not a compilation problem, you can see a class file generated if you navigate to your project folder. You will see this kind of error when you try to run a piece of code which do not have a main method...


how can i know that acm.program or acm.graphics does or doesnt have main in it?
 
sean slater
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i dont get what you guys mean.

I think my preprocessor segment is wrong.

i better learn 'Head First Java ' and get some clarity.

Thanks for your time and suggestions though.
 
bhanu chowdary
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I have misleaded you. I dont have any idea about this acm package you are using. I am sure somebody will help you on this one here in the forum.
In the meanwhile i will do some googling to find out what it is
 
bhanu chowdary
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sean, Try this.



I am able to run the code with out the main method.
 
bhanu chowdary
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bhanu chowdary wrote:I am able to run the code with out the main method.

Got it from this site.
it is possible to eliminate this method in many Java environments
. From the above link
 
James E Baker
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sean...

If you aren't comfortable with main() yet, then you probably are over your head with this code. Try something simple and learn how a class works before playing with the code you have here. Why don't you run this in Eclipse and get a feel for the format of a class.



Have fun!!!
 
bhanu chowdary
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to javaranch Sean
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!