954,176 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

java.lang.nosuchmethoderror main? please help

I am trying to compile this java file and it is giving me an error say : java.lang.nosuchmethodeorror.main

what could be the problem?

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 
public class JChangeFont extends JApplet implements ActionListener
{
   JLabel banner = new JLabel("Your Name");
   int fontSize = 18;
   Font theFont = new Font("TimesRoman",Font.BOLD, fontSize);
   JButton button1 = new JButton("Press");
   Container con = getContentPane();
   FlowLayout flow = new FlowLayout();
 
   public void init()
   {
      Container con = getContentPane();
      FlowLayout flow = new FlowLayout();
      con.setLayout(flow);
      banner.setFont(theFont);
      con.add(banner);
      con.add(button1);
      button1.addActionListener(this);
   }
 
   public void actionPerformed(ActionEvent e)
   {
     Object source = e.getSource();
     if (source == button1)
      {
        Font newFont = new Font("Helvetica",Font.ITALIC, fontSize +  10);
        banner.setFont(newFont);
 
     }
 
   }
 
 
 
}
JuneM
Newbie Poster
7 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

I am trying to compile this java file and it is giving me an error say : java.lang.nosuchmethodeorror.main

what could be the problem?

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 
public class JChangeFont extends JApplet implements ActionListener
{
   JLabel banner = new JLabel("Your Name");
   int fontSize = 18;
   Font theFont = new Font("TimesRoman",Font.BOLD, fontSize);
   JButton button1 = new JButton("Press");
   Container con = getContentPane();
   FlowLayout flow = new FlowLayout();
 
   public void init()
   {
      Container con = getContentPane();
      FlowLayout flow = new FlowLayout();
      con.setLayout(flow);
      banner.setFont(theFont);
      con.add(banner);
      con.add(button1);
      button1.addActionListener(this);
   }
 
   public void actionPerformed(ActionEvent e)
   {
     Object source = e.getSource();
     if (source == button1)
      {
        Font newFont = new Font("Helvetica",Font.ITALIC, fontSize +  10);
        banner.setFont(newFont);
 
     }
 
   }
 
 
 
}

and if I add this at the end

public static void main(String[]args)
{

JChangeFont applet = new JChangeFont();

Frame window = new Frame("JChangeFont");

window.setVisible(true);
}

}

}


I get several errors for public void main string saying : illegal start of expression

I am completely lost .... please help/

I appreciate it

JuneM
Newbie Poster
7 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

Is there a reason that your other thread on this wasn't sufficient?
http://www.daniweb.com/forums/thread264550.html

Ezzaral
Posting Genius
Moderator
15,985 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 
Is there a reason that your other thread on this wasn't sufficient? http://www.daniweb.com/forums/thread264550.html


This is different... and I think I am not bothering anyone by submitting a new thread in my acount here.

If you don't want to help, you don't have to reply to my thread.

thanks

JuneM
Newbie Poster
7 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

This is different... and I think I am not bothering anyone by submitting a new thread in my acount here.

If you don't want to help, you don't have to reply to my thread.

thanks

actually, Ezzaral is helping, and he is right: the sollution to this problem is mentioned in that other thread.
an applet is not supposed to have a main method, so if you're being bugged for one while running it, you're not running it the way you should be running an applet.
for some reason, your system thinks it's trying to run a standard Java application, instead of an applet

stultuske
Posting Sensei
3,110 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 432
 
actually, Ezzaral is helping, and he is right: the sollution to this problem is mentioned in that other thread. an applet is not supposed to have a main method, so if you're being bugged for one while running it, you're not running it the way you should be running an applet. for some reason, your system thinks it's trying to run a standard Java application, instead of an applet

When I registered to this website, I thought I would be getting some help. But you guys are not helping. I showed the work here and I am just trying to get help with the errors that I am getting when I try to compile the file.

I just don't get what you guys are saying? Java is new to me and I am learning it, I am taking this course online because I cannot attend college. That's why I am asking for help here, and little help. I am even saying guys please do this project for me.

Thanks for your replies though.

Thanks a lot.

JuneM
Newbie Poster
7 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

one last time:
you are running an applet as a Java application.
if you were not doing that, it wouldn't go looking for a main method.

so, sollution => run your applet as an applet.
this has been suggested to you several times, don't just ask, read the replies and try the suggestions out. you would've finished your work hours (if not days) ago

stultuske
Posting Sensei
3,110 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 432
 

This is different... and I think I am not bothering anyone by submitting a new thread in my acount here.

If you don't want to help, you don't have to reply to my thread.

thanks

No, it is not different. It is the same error that you inquired about in the other thread. And as far as "bothering anyone", you're violating this clause in the Keep It Organized rule of our forumsDo not flood the forum by posting the same question more than oncePerhaps you should review them before starting more threads for the same issue.

Ezzaral
Posting Genius
Moderator
15,985 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

The problem is solved in the other thread you have posted.....Enjoy!!

sincerelibran
Light Poster
41 posts since Mar 2009
Reputation Points: 8
Solved Threads: 15
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You