Results 1 to 16 of 16
  1. #1
    ZAXTHEGREAT is offline Member
    Join Date
    Jul 2007
    Posts
    10
    Rep Power
    0

    Default First Typed via video instruction

    Ok i have typed via video instruction my first program:D , but it didnt work.:(

    Im am currently using JCreator as my editor and this is the detailed info i used.

    Java Code:
    import java.awt.Canvas;
    import java.awt.Graphics;
    import java.awt.FontMetrics;
    import java.awt.Rectangle;
    
    class TextThree extends Canvas {
    	TextThree(){
    		setSize(300,100);
    	}
    	public void paint(Graphics g) {
    		Rectangle rect = getBounds();
    		FontMetrics fm = g.getFontMetrics();
    		String str;
    		int strwidth;
    		int x;
    		int y;
    		
    		str = "Top Left Corner";
    		y = fm.getAscent();
    		x = 0;
    		g.drawString(str,x,y);
    		
    		str = "Top Right Corner";
    		strwidth = fm.stringWidth(str);
    		y = fm.getAscent();
    		x = rect.width - strwidth;
    		g.drawString(str,x,y);
    		
    		str = "Bottom Left Corner";
    		y = rect.height - fm.getDescent();
    		x = 0;
    		g.drawString(str,x,y);
    		
    		str = "Bottom Right Corner";
    		strwidth = fm.stringWidth(str);
    		y = rect.height - fm.getDescent();
    		x = rect.width - strwidth;
    		g.drawString(str,x,y);
    		}
    }
    //But this is the error i get after compiling it and then running the file:confused:

    --------------------Configuration: test1 - JDK version 1.6.0_02 <Default> - <Default>--------------------
    java.lang.NoSuchMethodError: main
    Exception in thread "main"
    Process completed.

    Could you help me with this area thx

    ZAXTHEGREAT
    Last edited by JavaBean; 07-19-2007 at 03:41 PM. Reason: Code placed inside [code] tags.

  2. #2
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    10

    Default

    Quick answer: That errors tells you that the Java interpreter could not find a main method in your class. Java interpreter needs that method to run your code since it will start running your code from main method.

    Long Answer: Even if you make that code work successfully, as far as i see, it will nto do anything. So i recommend you a text based tutorial to start. Start with the following one. It is highly recommended. ;)

    Trail: Getting Started (The Java™ Tutorials)

  3. #3
    ZAXTHEGREAT is offline Member
    Join Date
    Jul 2007
    Posts
    10
    Rep Power
    0

    Default MMMmmm

    Well the gentleman that wrote the program successfully managed to create a window with four phrases stating the corner that they were in so it does work and i did check for any mistakes of mistype but there weren't any as when its compiled it says Process completed.

    By the what what do you mean when you say about the Method and the main

    cheers ZAX

  4. #4
    cruxblack is offline Senior Member
    Join Date
    Jul 2007
    Posts
    130
    Rep Power
    0

    Default

    da main method is the method that kinda..err..lets just say govern da process of ur class, ur primary class that is. If its an application, it must have a main method, like this

    Java Code:
    class TextThree extends Canvas {
          public static void main(String[] args){
          .......
          }
    }
    if its an applet, then u might not have to insert da main method, but rather da init method

    btw, if a program managed to be compiled perfectly, it doesnt always means that it's gonna run right

    i recommend reading bout java OOP logic from any of da links u can find, no matter how good a code was made, if da foundation are crumbling, da program wont have a safe path at all

    hope this helps ZAX :D

  5. #5
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    10

    Default

    If its an application, it must have a main method, like this
    I think that gentlemen should also describe how a canvas can be shown without a jframe :)

  6. #6
    ZAXTHEGREAT is offline Member
    Join Date
    Jul 2007
    Posts
    10
    Rep Power
    0

    Default Thx peeps

    Introduction_to_Java

    This is the video tutorial i am currently trying to follow by the way by a fella named Arthur Griffith.

  7. #7
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    10

    Default

    You forgot the link!

  8. #8
    cruxblack is offline Senior Member
    Join Date
    Jul 2007
    Posts
    130
    Rep Power
    0

    Default

    sori mr JBean :p
    i havent learned to much bout da canvas class, never use em...

    btw Zax, why using a tutorial video from that gentlemen u said there?
    isnt it easier if u just use da source code?:confused:

  9. #9
    ZAXTHEGREAT is offline Member
    Join Date
    Jul 2007
    Posts
    10
    Rep Power
    0

  10. #10
    ZAXTHEGREAT is offline Member
    Join Date
    Jul 2007
    Posts
    10
    Rep Power
    0

    Default

    Im only using the video to get some Java info and help but the sorce code i am using is JCreator which enables you to compile and run the file without going through the Cmd window.

  11. #11
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    10

    Default

    As far as we see you are not pasting all the code in the tutorial. As we said, at least a main method is missing. So check that wheether you are using whole code or not.

  12. #12
    ZAXTHEGREAT is offline Member
    Join Date
    Jul 2007
    Posts
    10
    Rep Power
    0

    Default Ok

    The code that i followed and typed in is exactly the way the gentlemen showed in the video i froze its image and spent ages just to make sure that the code was the same as his the only thing that i found was his worked lol wheres as mine didnt but the previous one i tryed like the "hello world" comment as a program worked fine,

    ZAX

    p.s. (by the way did you copy and paste my code to see if it worked)

  13. #13
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    10

    Default

    p.s. (by the way did you copy and paste my code to see if it worked)
    No it was missing a basic part so we saw it easily without trying :)

  14. #14
    cruxblack is offline Senior Member
    Join Date
    Jul 2007
    Posts
    130
    Rep Power
    0

    Default

    Just a minor correction,
    JCreator is an IDE, a working environment filled with tools to ease the work of creating projects in Java,
    The term source codes usually (in Java language) refers to the .java file in which the codes was written, did the video include the complete source code in plain text .java file as well?

    Just like Mr. JavaBean said, ur code isn't an applet, so it is missing a main method, applications must have at least 1 main method to be able to execute

    I wonder, maybe there's another class linked to this one?
    Maybe that's where the main method are, try to check the other videos available

    Just like Mr. J there, i also recommend a text based tutorial to start, and also, try to find more references bout classes, constructors and methods, learning by doing is useful, but an xtra menu of concepts won't hurt either right :D

  15. #15
    ZAXTHEGREAT is offline Member
    Join Date
    Jul 2007
    Posts
    10
    Rep Power
    0

    Default Cheers

    hey thanks guys for ya help i presume i was using an object method instead of a text method am i correct with that or not, oh and Java dude man could you sow me exactly what you did to make it work it would be of help just for the interest

    ZAX:D

  16. #16
    cruxblack is offline Senior Member
    Join Date
    Jul 2007
    Posts
    130
    Rep Power
    0

    Default

    What u mean object method and text method Zax? I don't really get it :confused:
    to make it work, i suggest u look for another class, i think this class is used by a main class, but u didn't compile the main class, try looking in that video tutorial of urs

Similar Threads

  1. Video tutorial on EJB
    By mdeepaks in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 01-31-2009, 05:57 AM
  2. Replies: 0
    Last Post: 01-19-2008, 09:04 AM
  3. can I have video out using USB data
    By papa_china in forum CLDC and MIDP
    Replies: 0
    Last Post: 07-29-2007, 04:29 AM
  4. Char type for first character typed?
    By Sageinquisitor in forum New To Java
    Replies: 3
    Last Post: 07-17-2007, 07:08 AM
  5. video stream
    By Alan in forum Advanced Java
    Replies: 2
    Last Post: 05-17-2007, 08:12 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
  •