ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm taking a java course this fall at the local community college.
I thought I'd get a jump on the course so I bought " The Java Tutorial - Third Edition,recommended by Amazon.com.
The book is for j2sdk1.3.1. I downloaded j2sdk1.4.2. Will the newer compiler cause program errors when I do the exercises? I copied the code exactly, javac is ok, creates the class file, but when I try java I get:"Execption in thread "main" java.lang.NoSuchMethodError: main
Thanks -- Larry
method somewhere in the class which you are executing. This is where your program will start when you do "java mainClass" or whatever your class is called.
public class ClickMe extends Applet implements MouseListener {
private Spot spot = null;
private static final int RADIUS = 7;
public void init() {
addMouseListener(this);
}
public void paint(Graphics g) {
//draw a black border and a white background
g.setColor(Color.white);
g.fillRect(0, 0, getSize().width - 1, getSize().height - 1);
g.setColor(Color.black);
g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);
//draw the spot
g.setColor(Color.red);
if (spot != null) {
g.fillOval(spot.x - RADIUS, spot.y - RADIUS, RADIUS * 2, RADIUS * 2);
}
}
public void mousePressed(MouseEvent event) {
if (spot == null) {
spot = new Spot(RADIUS);
}
spot.x = event.getX();
spot.y = event.getY();
repaint();
}
public void mouseClicked(MouseEvent event) {}
public void mouseReleased(MouseEvent event) {}
public void mouseEntered(MouseEvent event) {}
public void mouseExited(MouseEvent event) {}
}
It's the same on the tutorial cd that came with the book, it's the same at their website(it's a sun microsystems book.
I don't think they want me to start rewriting code already, but
as dave_starsky stated; also clearly stated in the book:
public static void main(String [] args)
must be used to start all applications.
I can place this above the 4th line of code, if it works.
You've written an applet, you don't need a main to start it. You need to embed it in an html page to view it (either through the browser or the appletviewer).
Compile your code (javac), but obviously don't try to run it.
Then create an html file like this (change the applet attributes though)
Thanks coolman0stress, that worked. It was also in the book. I'm trying to do 15 things at once. I should have reviewed better. My fault. Thanks for the reply.
Larry
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.