943,107 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 649
  • Java RSS
Mar 3rd, 2010
0

java.lang.nosuchmethoderror main? please help

Expand Post »
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?

  1.  
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5.  
  6. public class JChangeFont extends JApplet implements ActionListener
  7. {
  8. JLabel banner = new JLabel("Your Name");
  9. int fontSize = 18;
  10. Font theFont = new Font("TimesRoman",Font.BOLD, fontSize);
  11. JButton button1 = new JButton("Press");
  12. Container con = getContentPane();
  13. FlowLayout flow = new FlowLayout();
  14.  
  15. public void init()
  16. {
  17. Container con = getContentPane();
  18. FlowLayout flow = new FlowLayout();
  19. con.setLayout(flow);
  20. banner.setFont(theFont);
  21. con.add(banner);
  22. con.add(button1);
  23. button1.addActionListener(this);
  24. }
  25.  
  26. public void actionPerformed(ActionEvent e)
  27. {
  28. Object source = e.getSource();
  29. if (source == button1)
  30. {
  31. Font newFont = new Font("Helvetica",Font.ITALIC, fontSize + 10);
  32. banner.setFont(newFont);
  33.  
  34. }
  35.  
  36. }
  37.  
  38.  
  39.  
  40. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JuneM is offline Offline
7 posts
since Feb 2010
Mar 3rd, 2010
0
Re: java.lang.nosuchmethoderror main? please help
Click to Expand / Collapse  Quote originally posted by JuneM ...
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?

  1.  
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5.  
  6. public class JChangeFont extends JApplet implements ActionListener
  7. {
  8. JLabel banner = new JLabel("Your Name");
  9. int fontSize = 18;
  10. Font theFont = new Font("TimesRoman",Font.BOLD, fontSize);
  11. JButton button1 = new JButton("Press");
  12. Container con = getContentPane();
  13. FlowLayout flow = new FlowLayout();
  14.  
  15. public void init()
  16. {
  17. Container con = getContentPane();
  18. FlowLayout flow = new FlowLayout();
  19. con.setLayout(flow);
  20. banner.setFont(theFont);
  21. con.add(banner);
  22. con.add(button1);
  23. button1.addActionListener(this);
  24. }
  25.  
  26. public void actionPerformed(ActionEvent e)
  27. {
  28. Object source = e.getSource();
  29. if (source == button1)
  30. {
  31. Font newFont = new Font("Helvetica",Font.ITALIC, fontSize + 10);
  32. banner.setFont(newFont);
  33.  
  34. }
  35.  
  36. }
  37.  
  38.  
  39.  
  40. }
and if I add this at the end

  1.  
  2. public static void main(String[]args)
  3. {
  4.  
  5. JChangeFont applet = new JChangeFont();
  6.  
  7. Frame window = new Frame("JChangeFont");
  8.  
  9. window.setVisible(true);
  10. }
  11.  
  12. }
  13.  
  14. }

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

I am completely lost .... please help/

I appreciate it
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JuneM is offline Offline
7 posts
since Feb 2010
Mar 3rd, 2010
0
Re: java.lang.nosuchmethoderror main? please help
Is there a reason that your other thread on this wasn't sufficient?
http://www.daniweb.com/forums/thread264550.html
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,754 posts
since May 2007
Mar 4th, 2010
0
Re: java.lang.nosuchmethoderror main? please help
Click to Expand / Collapse  Quote originally posted by Ezzaral ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JuneM is offline Offline
7 posts
since Feb 2010
Mar 4th, 2010
0
Re: java.lang.nosuchmethoderror main? please help
Click to Expand / Collapse  Quote originally posted by JuneM ...
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
Reputation Points: 899
Solved Threads: 347
Nearly a Posting Maven
stultuske is offline Offline
2,428 posts
since Jan 2007
Mar 4th, 2010
0
Re: java.lang.nosuchmethoderror main? please help
Click to Expand / Collapse  Quote originally posted by stultuske ...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JuneM is offline Offline
7 posts
since Feb 2010
Mar 4th, 2010
0
Re: java.lang.nosuchmethoderror main? please help
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
Reputation Points: 899
Solved Threads: 347
Nearly a Posting Maven
stultuske is offline Offline
2,428 posts
since Jan 2007
Mar 4th, 2010
0
Re: java.lang.nosuchmethoderror main? please help
Click to Expand / Collapse  Quote originally posted by JuneM ...
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 forums
Quote ...
Do not flood the forum by posting the same question more than once
Perhaps you should review them before starting more threads for the same issue.
Last edited by Ezzaral; Mar 4th, 2010 at 10:19 pm.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,754 posts
since May 2007
Mar 5th, 2010
0
Re: java.lang.nosuchmethoderror main? please help
The problem is solved in the other thread you have posted.....Enjoy!!
Reputation Points: 8
Solved Threads: 15
Light Poster
sincerelibran is offline Offline
41 posts
since Mar 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: IO Files and Multithreading
Next Thread in Java Forum Timeline: Problem with setting up a network for a tictactoe protocoll.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC