Results 1 to 16 of 16
- 07-19-2007, 03:34 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 10
- Rep Power
- 0
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.
//But this is the error i get after compiling it and then running the file:confused: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); } }
--------------------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
ZAXTHEGREATLast edited by JavaBean; 07-19-2007 at 03:41 PM. Reason: Code placed inside [code] tags.
- 07-19-2007, 03:43 PM #2
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)
- 07-19-2007, 03:53 PM #3
Member
- Join Date
- Jul 2007
- Posts
- 10
- Rep Power
- 0
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
- 07-19-2007, 05:10 PM #4
Senior Member
- Join Date
- Jul 2007
- Posts
- 130
- Rep Power
- 0
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
if its an applet, then u might not have to insert da main method, but rather da init methodJava Code:class TextThree extends Canvas { public static void main(String[] args){ ....... } }
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
- 07-19-2007, 05:14 PM #5
I think that gentlemen should also describe how a canvas can be shown without a jframe :)If its an application, it must have a main method, like this
- 07-19-2007, 05:42 PM #6
Member
- Join Date
- Jul 2007
- Posts
- 10
- Rep Power
- 0
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.
- 07-19-2007, 06:17 PM #7
You forgot the link!
- 07-19-2007, 06:27 PM #8
Senior Member
- Join Date
- Jul 2007
- Posts
- 130
- Rep Power
- 0
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:
- 07-20-2007, 01:20 PM #9
Member
- Join Date
- Jul 2007
- Posts
- 10
- Rep Power
- 0
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
- 07-20-2007, 01:22 PM #10
Member
- Join Date
- Jul 2007
- Posts
- 10
- Rep Power
- 0
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.
- 07-20-2007, 03:26 PM #11
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.
- 07-20-2007, 05:41 PM #12
Member
- Join Date
- Jul 2007
- Posts
- 10
- Rep Power
- 0
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)
- 07-20-2007, 05:45 PM #13
No it was missing a basic part so we saw it easily without trying :)p.s. (by the way did you copy and paste my code to see if it worked)
- 07-20-2007, 05:45 PM #14
Senior Member
- Join Date
- Jul 2007
- Posts
- 130
- Rep Power
- 0
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
- 07-20-2007, 11:12 PM #15
Member
- Join Date
- Jul 2007
- Posts
- 10
- Rep Power
- 0
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
- 07-23-2007, 04:27 PM #16
Senior Member
- Join Date
- Jul 2007
- Posts
- 130
- Rep Power
- 0
Similar Threads
-
Video tutorial on EJB
By mdeepaks in forum Enterprise JavaBeans (EJB)Replies: 1Last Post: 01-31-2009, 05:57 AM -
Is there anyone can give a instruction about Myoodb
By ibmzz in forum JDBCReplies: 0Last Post: 01-19-2008, 09:04 AM -
can I have video out using USB data
By papa_china in forum CLDC and MIDPReplies: 0Last Post: 07-29-2007, 04:29 AM -
Char type for first character typed?
By Sageinquisitor in forum New To JavaReplies: 3Last Post: 07-17-2007, 07:08 AM -
video stream
By Alan in forum Advanced JavaReplies: 2Last Post: 05-17-2007, 08:12 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks