|
|
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.
|
|

07-19-2007, 04:34 PM
|
|
Member
|
|
Join Date: Jul 2007
Posts: 10
|
|
|
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.
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.
|
|

07-19-2007, 04:43 PM
|
 |
Moderator
|
|
Join Date: May 2007
Posts: 1,272
|
|
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, 04:53 PM
|
|
Member
|
|
Join Date: Jul 2007
Posts: 10
|
|
|
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, 06:10 PM
|
|
Senior Member
|
|
Join Date: Jul 2007
Posts: 130
|
|
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
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 
|
|

07-19-2007, 06:14 PM
|
 |
Moderator
|
|
Join Date: May 2007
Posts: 1,272
|
|
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 
|
|

07-19-2007, 06:42 PM
|
|
Member
|
|
Join Date: Jul 2007
Posts: 10
|
|
|
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, 07:17 PM
|
 |
Moderator
|
|
Join Date: May 2007
Posts: 1,272
|
|
|
You forgot the link!
|
|

07-19-2007, 07:27 PM
|
|
Senior Member
|
|
Join Date: Jul 2007
Posts: 130
|
|
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? 
|
|

07-20-2007, 02:20 PM
|
|
Member
|
|
Join Date: Jul 2007
Posts: 10
|
|
|
|
|

07-20-2007, 02:22 PM
|
|
Member
|
|
Join Date: Jul 2007
Posts: 10
|
|
|
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, 04:26 PM
|
 |
Moderator
|
|
Join Date: May 2007
Posts: 1,272
|
|
|
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, 06:41 PM
|
|
Member
|
|
Join Date: Jul 2007
Posts: 10
|
|
|
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, 06:45 PM
|
 |
Moderator
|
|
Join Date: May 2007
Posts: 1,272
|
|
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 
|
|

07-20-2007, 06:45 PM
|
|
Senior Member
|
|
Join Date: Jul 2007
Posts: 130
|
|
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 
|
|

07-21-2007, 12:12 AM
|
|
Member
|
|
Join Date: Jul 2007
Posts: 10
|
|
|
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 
|
|

07-23-2007, 05:27 PM
|
|
Senior Member
|
|
Join Date: Jul 2007
Posts: 130
|
|
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
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|