Results 1 to 20 of 22
Thread: Java compiling error
- 10-14-2009, 04:34 AM #1
Member
- Join Date
- Oct 2009
- Posts
- 11
- Rep Power
- 0
Java compiling error
Hi guys,
I am new to Java, and I am setting my computer up.
I am able to compile simple syntax. Now I am trying to run one of the examples that seems to call out java.awt and java.awat.event
I am getting errors.
I am able to compile it, but getting error when trying to run it.Java Code:import java.awt.*; import java.awt.event.*; class party{ public void buildInvite(){ Frame f=new Frame(); Label i=new Label("Party at Tim"); Button b=new Button("You bet"); Button c=new Button("Shoot me"); Panel p=new Panel(); p.add(i); } }
//Exception in Thread "main" java.lang.NoSuchMethodError: main//:confused:
-
Your code in fact doesn't have a main method. It can be compiled and can be used by other classes, but this class as written can't be run as you need a main method to run anything (except an applet). You may do well to check out the Sun Java tutorials and go through them.
Sun Java Tutorials
- 10-14-2009, 04:47 AM #3
Member
- Join Date
- Oct 2009
- Posts
- 11
- Rep Power
- 0
Thanks for your quick reply.
Okay I will go through their website.
Can I ask you one more question:
where can I download J2SE API?
and should they be in the bin folder?
- 10-14-2009, 05:23 AM #4
Member
- Join Date
- Oct 2009
- Posts
- 11
- Rep Power
- 0
:confused:
it is not even compiling :(Java Code:public class DooBee{ public static void main (String[]args){ int x=1; while (x<3){ system.out.print("Doo"); system.out.print("Bee"); x=x+1; } if (x==3){ system.out.print("Do"); } } }
please help. need to understand the problem.
-
The compiler errors will tell you what's wrong, and learning to read and understand them will be a big step in your Java education.
Notice them telling you that it doesn't understand what "system" is. The reason is that capitalization matters in Java. Try using "System" instead and see if it compiles.
Much luck!
- 10-14-2009, 05:35 AM #6
Member
- Join Date
- Oct 2009
- Posts
- 11
- Rep Power
- 0
Thank you. Yes indeed it was the Capital letter.
I guess I am gonna learn Java the hard and Long way :)
:o
-
- 10-14-2009, 02:01 PM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 10-14-2009, 03:40 PM #9
Member
- Join Date
- Oct 2009
- Posts
- 11
- Rep Power
- 0
I think I downloaded the right one.Cause I went to java.sun web, and downloaded "jdk-6u16-windows-i586.exe" same as "JDK 6 Update 16" link.
Is this correct?
If not, can you give me some guidance?
- 10-14-2009, 03:48 PM #10
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Yep of course you've got the JDK. That's why you are able to compile code and get compilation error messages.
The API specs are available here.
Pick the one labeled Java SE 6 Documentation.
- 10-14-2009, 03:55 PM #11
Member
- Join Date
- Oct 2009
- Posts
- 11
- Rep Power
- 0
As for the API, Honestly I am still new. I am reading a book " Head first for Java" and they asked me to download API docs. I am not sure what it is for, but it seems to me as if they are a set of classes that I can import into the program. Probably I am wrong.
This is why the first code I posted has import java.awt.* and I am not sure if they are related.
Can you tell me guys how to fix my first code?
- 10-14-2009, 04:20 PM #12
Member
- Join Date
- Oct 2009
- Posts
- 11
- Rep Power
- 0
What do we use the specs for?
- 10-14-2009, 04:22 PM #13
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
You already have the classes you are importing. You got them when you downloaded the JDK. The API specs explain what those classes do. They are the documentation of the standard Java classes.
What exactly do you want to have fixed in your code?
Post the current code you have and the error messages if any you are receiving.
- 10-14-2009, 05:19 PM #14
Member
- Join Date
- Oct 2009
- Posts
- 11
- Rep Power
- 0
this is the error message I am getting when I type in command prompt java partyJava Code:import java.awt.*; import java.awt.event.*; class party{ public void buildInvite(){ Frame f=new Frame(); Label i=new Label("Party at Tim"); Button b=new Button("You bet"); Button c=new Button("Shoot me"); Panel p=new Panel(); p.add(i); } }
Exception in Thread "main" java.lang.NoSuchMethodError: main
- 10-14-2009, 08:38 PM #15
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Oh dear. Did you somehow miss the first reply in this thread?
- 10-15-2009, 01:40 AM #16
Member
- Join Date
- Oct 2009
- Posts
- 11
- Rep Power
- 0
I did see it, and I did try it, it gave me the same error.
I posted the wrong code in my last reply.
this is what I have put.
So I have tried to look more and understand what is going on, so I modified the code to this.Java Code:import java.awt.*; import java.awt.event.*; class party{ public void main (){ Frame f=new Frame(); Label i=new Label("Party at Tim"); Button b=new Button("You bet"); Button c=new Button("Shoot me"); Panel p=new Panel(); p.add(i); } }
Java Code:import java.awt.*; import java.awt.event.*; [B]public[/B] class party{ public [B]static[/B] void main (String[]args){ Frame f=new Frame(); Label i=new Label("Party at Tim"); Button b=new Button("You bet"); Button c=new Button("Shoot me"); Panel p=new Panel(); p.add(i); } }
So it gave me this error, which I don't understand what it means
error:Class names, 'party', are on;ly accepted if annotation processing is explicitly requested.
I appreciate your patience.
- 10-15-2009, 02:10 AM #17
Member
- Join Date
- Oct 2009
- Posts
- 11
- Rep Power
- 0
I found the solution for the problem: I was typing Javac party instead of Java party to run it.
Now no errors, But nothing happened.
Do I have to run the program from command prompt ?
-
Your GUI doesn't show because you never tell it to show, but don't try to start out with GUI programming as it adds a whole other layer of complexity that you don't need right now.
-
and sorry for being blunt, but believe me, you'll save yourself a world of grief by putting GUI on hold for just a little bit. Solidify your syntax first, and you'll have a much more rewarding time in GUI.
- 10-15-2009, 02:41 AM #20
Member
- Join Date
- Oct 2009
- Posts
- 11
- Rep Power
- 0
Similar Threads
-
Having error while compiling
By Kodeee in forum New To JavaReplies: 12Last Post: 03-17-2009, 11:08 AM -
Compiling error in JCreator
By ddatta8 in forum New To JavaReplies: 0Last Post: 12-03-2008, 05:27 AM -
Compiling error
By lawksalih in forum New To JavaReplies: 6Last Post: 01-29-2008, 07:26 PM -
Error during compiling
By boy22 in forum New To JavaReplies: 2Last Post: 08-03-2007, 02:42 AM -
Error while compiling
By ai_2007 in forum Advanced JavaReplies: 1Last Post: 07-01-2007, 11:37 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks