Page 1 of 2 12 LastLast
Results 1 to 20 of 22
  1. #1
    fadijava is offline Member
    Join Date
    Oct 2009
    Posts
    11
    Rep Power
    0

    Default 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.
    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);
    	}
    }
    I am able to compile it, but getting error when trying to run it.
    //Exception in Thread "main" java.lang.NoSuchMethodError: main//:confused:

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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

  3. #3
    fadijava is offline Member
    Join Date
    Oct 2009
    Posts
    11
    Rep Power
    0

    Thumbs up

    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?

  4. #4
    fadijava is offline Member
    Join Date
    Oct 2009
    Posts
    11
    Rep Power
    0

    Default

    :confused:

    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");
    		}
    	}
    }
    it is not even compiling :(
    please help. need to understand the problem.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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!

  6. #6
    fadijava is offline Member
    Join Date
    Oct 2009
    Posts
    11
    Rep Power
    0

    Default

    Thank you. Yes indeed it was the Capital letter.
    I guess I am gonna learn Java the hard and Long way :)
    :o

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by fadijava View Post
    Thank you. Yes indeed it was the Capital letter.
    Yep, and you're welcome.
    I guess I am gonna learn Java the hard and Long way :)
    :o
    Is there any other way? Heck the challenge is half the fun.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by fadijava View Post
    where can I download J2SE API?
    and should they be in the bin folder?
    What you exactly mean by API? I hope you've installed the latest SDK version. Are you talking about Java doc API?

  9. #9
    fadijava is offline Member
    Join Date
    Oct 2009
    Posts
    11
    Rep Power
    0

    Default

    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. #10
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    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.

  11. #11
    fadijava is offline Member
    Join Date
    Oct 2009
    Posts
    11
    Rep Power
    0

    Default

    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?

  12. #12
    fadijava is offline Member
    Join Date
    Oct 2009
    Posts
    11
    Rep Power
    0

    Default

    What do we use the specs for?

  13. #13
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    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.

  14. #14
    fadijava is offline Member
    Join Date
    Oct 2009
    Posts
    11
    Rep Power
    0

    Default

    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);
    	}
    }
    this is the error message I am getting when I type in command prompt java party
    Exception in Thread "main" java.lang.NoSuchMethodError: main

  15. #15
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Oh dear. Did you somehow miss the first reply in this thread?

  16. #16
    fadijava is offline Member
    Join Date
    Oct 2009
    Posts
    11
    Rep Power
    0

    Default

    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.
    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);
    	}
    }
    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.*;
    [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.

  17. #17
    fadijava is offline Member
    Join Date
    Oct 2009
    Posts
    11
    Rep Power
    0

    Default

    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 ?

  18. #18
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  19. #19
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  20. #20
    fadijava is offline Member
    Join Date
    Oct 2009
    Posts
    11
    Rep Power
    0

    Default

    Oh no worries, your honesty is what matters.
    I am going to follow your advice.
    I have one last question:
    I keep seeing people referencing NetBeans, is it a JVM?

Page 1 of 2 12 LastLast

Similar Threads

  1. Having error while compiling
    By Kodeee in forum New To Java
    Replies: 12
    Last Post: 03-17-2009, 11:08 AM
  2. Compiling error in JCreator
    By ddatta8 in forum New To Java
    Replies: 0
    Last Post: 12-03-2008, 05:27 AM
  3. Compiling error
    By lawksalih in forum New To Java
    Replies: 6
    Last Post: 01-29-2008, 07:26 PM
  4. Error during compiling
    By boy22 in forum New To Java
    Replies: 2
    Last Post: 08-03-2007, 02:42 AM
  5. Error while compiling
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 07-01-2007, 11:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •