Hi everyone

I need to hand in this assignment today :(
Im trying to read from a file and read it onto the screen, my code keeps showing up an error saying 'java.lang.NoSuchMethodError: Main'

Here is my code:

import java.io.*;
import java.awt.*;
import java.applet.*;

public class Empty_3 extends Applet {

  TextArea ta = new TextArea();

  public void init() 
  public static void main(String args[])
  {
    setLayout(new BorderLayout());
    add(ta, BorderLayout.CENTER);
    try {
      InputStream in = 
        getClass().getResourceAsStream("test1.txt"); 
      InputStreamReader isr = 
        new InputStreamReader(in);
      BufferedReader br = 
        new BufferedReader(isr);
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      String line;
       while ((line = br.readLine()) != null) {
        pw.println(line);
      }
      ta.setText(sw.toString());
    } catch (IOException io) {
      ta.setText("Ooops");
    }
  }
} 

Can anyone help me please?

Thankyou

Matt

Edited 3 Years Ago by mike_2000_17: Fixed formatting

If you paid more attention in your classes you would know that Applet DO NOT USE "main" class call. For more info follow Sun Applet tutorials here

Comments
Good correction, I should stay with c++ not java ;)

well thats what i did at first but it came up with this error?

'missing method body, or declare abstract'
under the public void init()

so do you know where to go from there?

If you paid more attention in your classes you would know that Applet DO NOT USE "main" class call. For more info follow Sun Applet tutorials here

well thats what i did at first but it came up with this error?

'missing method body, or declare abstract'
under the public void init()

so do you know where to go from there?

Well drop the code as you had before or how it should be based on the assistance of the link (please do not forget to use code tags, just simply click on the hash sign "#" in advanced editing options, "Go Advanced" will get you there) and some short explanation of you trying to do would be nice

For starters, this is not a valid method body

public void init()

This is

public void init() {
    // stuff
}

everything is urgent, it seems. people need to start posting their questions with subject headings like:

"Help Help!! Life or Death Problem Here!!!"

or maybe

"OMG MY ASS IS ON FIRE AND MY HEAD IS A-CATCHIN', SUMBODY PLS ANSWER MY Q!!!"

otherwise, im gonna get bogged down trying to answer all these merely "urgent" questions.

.

yah. It's no different in customer support. Customers flag every single issue as critical, with the inevitable result that we stop looking at that flag and determine ourselves what's important...

Comments
lol ... try working on an anti-malware team. some people are funny. and by funny, i mean stupid :P

One of our teacher who used to work at the Supply Management of a company (logistics) told us that everybody where making requests for supplies saying that it was extremely urgent, so he could not decide which request to handle first.
Then he came up with the idea not to do anything and wait who would complain first about the delay and handle their request first

Comments
I like the way your teacher sorted problem ;)

For one, it's

public static void main(String [] args) {}

Not

public static void main(String args[]) {}

hello,
your error might be in the function declairation section, where you have used
TextArea t=new TextArea();
rather it should be like this.

TextArea t=new TextArea("");
i am sure that your program will work this way.
good bye.

hello,
your error might be in the function declairation section, where you have used
TextArea t=new TextArea();
rather it should be like this.

TextArea t=new TextArea("");
i am sure that your program will work this way.
good bye.

That is also wrong. Both declarations are correct. If you read the API for JTextArea, and I have, you will see that there are many constructors and the TextArea t=new TextArea(); is correct.

This article has been dead for over six months. Start a new discussion instead.