Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 06-30-2004, 01:53 PM   #1
Registered: Jan 2004
Location: Fairport, NY
Distribution: Arch/Ubuntu
Posts: 42

Rep: Reputation: 15
newbie java question

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
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
Old 06-30-2004, 02:00 PM   #2
Registered: May 2004
Location: At Keyboard
Distribution: Mandrake 10.0, SuSE 9.0
Posts: 114

Rep: Reputation: 15
Is there a main method in the file you are compiling? What command are you executing to compile?
Old 06-30-2004, 03:19 PM   #3
Registered: Oct 2003
Location: UK, Manchester
Distribution: Gentoo (2.6.10-r4) & Ubuntu
Posts: 145

Rep: Reputation: 16
What you need to do is make sure that you have a

public static void main(String [] args)
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.
Old 06-30-2004, 04:21 PM   #4
Registered: Jan 2004
Location: Fairport, NY
Distribution: Arch/Ubuntu
Posts: 42

Original Poster
Rep: Reputation: 15
This is the code:

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class ClickMe extends Applet implements MouseListener {
private Spot spot = null;
private static final int RADIUS = 7;

public void init() {

public void paint(Graphics g) {
//draw a black border and a white background
g.fillRect(0, 0, getSize().width - 1, getSize().height - 1);
g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);

//draw the spot
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();
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.

thanks for the reply -- Larry
Old 06-30-2004, 05:06 PM   #5
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Tribblix, Ubuntu/WSL
Posts: 9,768

Rep: Reputation: 468Reputation: 468Reputation: 468Reputation: 468Reputation: 468
main method is needed for applications entry classes, while your class is an applet, so doesn't need a main.
Old 06-30-2004, 05:13 PM   #6
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
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)
  <applet code="MyJava.class" width="300" height="200">
Then run it either through the browser (open the html file) or the appletviewer:
appletviewer MyJavaHtml.html
Also, you should use JApplet instead of Applet now.
Old 06-30-2004, 05:34 PM   #7
Registered: Jan 2004
Location: Fairport, NY
Distribution: Arch/Ubuntu
Posts: 42

Original Poster
Rep: Reputation: 15
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie question on java coolguy_iiit Programming 6 05-12-2005 01:47 PM
newbie java swing question... window size true_atlantis Programming 1 10-07-2004 11:17 AM
A very basic newbie question on Java lmellen Programming 5 07-19-2004 04:59 PM
Java Newbie Question patpawlowski Programming 6 02-27-2004 05:25 PM
Newbie question about executing java command oldoldcat Linux - General 4 01-30-2004 02:15 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:25 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration