Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-19-2007, 04:34 PM
Member
 
Join Date: Jul 2007
Posts: 10
ZAXTHEGREAT is on a distinguished road
First Typed via video instruction
Ok i have typed via video instruction my first program , but it didnt work.

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

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

--------------------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 04:41 PM. Reason: Code placed inside [code] tags.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-19-2007, 04:43 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
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)
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-19-2007, 04:53 PM
Member
 
Join Date: Jul 2007
Posts: 10
ZAXTHEGREAT is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-19-2007, 06:10 PM
Senior Member
 
Join Date: Jul 2007
Posts: 130
cruxblack will become famous soon enough
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

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
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-19-2007, 06:14 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
Quote:
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
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 07-19-2007, 06:42 PM
Member
 
Join Date: Jul 2007
Posts: 10
ZAXTHEGREAT is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 07-19-2007, 07:17 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
You forgot the link!
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 07-19-2007, 07:27 PM
Senior Member
 
Join Date: Jul 2007
Posts: 130
cruxblack will become famous soon enough
sori mr JBean
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?
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 07-20-2007, 02:20 PM
Member
 
Join Date: Jul 2007
Posts: 10
ZAXTHEGREAT is on a distinguished road
Java: Introduction to the Java Programming Language Video Tutorials, Java: Introduction to the Java Programming Language Tutorials

sorry about that i didnt paste the link to the video tutorials
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 07-20-2007, 02:22 PM
Member
 
Join Date: Jul 2007
Posts: 10
ZAXTHEGREAT is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 07-20-2007, 04:26 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 07-20-2007, 06:41 PM
Member
 
Join Date: Jul 2007
Posts: 10
ZAXTHEGREAT is on a distinguished road
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)
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 07-20-2007, 06:45 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
Quote:
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
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 07-20-2007, 06:45 PM
Senior Member
 
Join Date: Jul 2007
Posts: 130
cruxblack will become famous soon enough
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
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 07-21-2007, 12:12 AM
Member
 
Join Date: Jul 2007
Posts: 10
ZAXTHEGREAT is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 07-23-2007, 05:27 PM
Senior Member
 
Join Date: Jul 2007
Posts: 130
cruxblack will become famous soon enough
What u mean object method and text method Zax? I don't really get it
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there anyone can give a instruction about Myoodb ibmzz Database 0 01-19-2008 10:04 AM
Video tutorial on EJB mdeepaks Enterprise JavaBeans 0 12-05-2007 04:33 AM
can I have video out using USB data papa_china CLDC and MIDP 0 07-29-2007 05:29 AM
Char type for first character typed? Sageinquisitor New To Java 3 07-17-2007 08:08 AM
video stream Alan Advanced Java 2 05-17-2007 09:12 AM


All times are GMT +3. The time now is 06:00 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org