![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Sep 2004
Posts: 10
Rep Power: 0
![]() |
i done this program,but when i execute the program,computer will display
"Exception in thread" main"java.lang.NosuchMethodError:main" y ah? any 1 can help me?? Below are my coding import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Project extends JApplet implements ActionListener { CheckboxGroup p = new CheckboxGroup(); Checkbox NONE = new Checkbox("NONE",p,true); Checkbox LAN1001 = new Checkbox("LAN1001",p,false); Checkbox LAN1003 = new Checkbox("LAN1003",p,false); Checkbox LAN1005 = new Checkbox("LAN1005",p,false); JTextField name, icno, csc230, csc231, csc239, mgt227, enl205, result1, result2, result3, result4, lan1; JButton Calculatebutton; public void init() { Container container= getContentPane(); JLabel data1Label= new JLabel ("BMS SEM1"); JLabel space2Label= new JLabel (""); JLabel dataLabel= new JLabel (" Please enter your marks to get your grade:"); JLabel spaceLabel = new JLabel (""); JLabel nameLabel= new JLabel ("Student name"); JLabel icnoLabel = new JLabel ("ICNO"); JLabel space1Label= new JLabel (""); JLabel csc230Label= new JLabel ("CSC230"); JLabel csc231Label= new JLabel ("CSC231"); JLabel csc239Label= new JLabel ("CSC239"); JLabel mgt227Label= new JLabel ("MGT227"); JLabel enl205Label= new JLabel ("ENL205"); JLabel spaceLabel2= new JLabel (" "); JLabel info= new JLabel ("if you are not taking please enter 0 in the textbar:"); JLabel spaceLabel1= new JLabel (""); name= new JTextField (20); icno= new JTextField (20); csc230= new JTextField (7); csc231= new JTextField (7); csc239= new JTextField (7); mgt227= new JTextField (7); enl205= new JTextField (7); result1= new JTextField (75); result2= new JTextField (75); result3= new JTextField (75); result4= new JTextField (75); lan1= new JTextField (7); Calculatebutton= new JButton ("Enter"); container.setLayout (new FlowLayout (FlowLayout.LEFT)); container.add (data1Label); container.add (space2Label); container.add (dataLabel); container.add (spaceLabel); container.add (nameLabel); container.add (name); container.add (icnoLabel); container.add (icno); container.add (space1Label); container.add (csc230Label); container.add (csc230); container.add (csc231Label); container.add (csc231); container.add (csc239Label); container.add (csc239); container.add (mgt227Label); container.add (mgt227); container.add (enl205Label); container.add (enl205); container.add (spaceLabel2); container.add (info); container.add (spaceLabel1); container.add (NONE); container.add (LAN1001); container.add (LAN1003); container.add (LAN1005); container.add (lan1); container.add (result1); result1.setEditable (false); container.add (result2); result2.setEditable (false); container.add (result3); result3.setEditable (false); container.add (result4); result4.setEditable (false); Calculatebutton.addActionListener (this); container.add (Calculatebutton); } public void actionPerformed (ActionEvent e) { String g1, g2, g3, g4, g5, ag, lann1; float avg, total; float a =Integer.parseInt (csc230.getText()); float b =Integer.parseInt (csc231.getText()); float c =Integer.parseInt (csc239.getText()); float d =Integer.parseInt (mgt227.getText()); float x =Integer.parseInt (enl205.getText()); float la1=Integer.parseInt (lan1.getText()); String y = icno.getText(); String z = name.getText(); if(a<=100 && a>70) g1 = "A"; else if(a<=69 && a>50) g1 = "B"; else if(a<=50 && a>40) g1 = "C"; else g1 = "D"; if(b<=100 && b>70) g2 = "A"; else if(b<=69 && b>50) g2 = "B"; else if(b<=50 && b>40) g2 = "C"; else g2 = "D"; if(c<=100 && c>70) g3 = "A"; else if(c<=69 && c>50) g3 = "B"; else if(c<=50 && c>40) g3 = "C"; else g3 = "D"; if(d<=100 && d>70) g4 = "A"; else if(d<=69 && d>50) g4 = "B"; else if(d<=50 && d>40) g4 = "C"; else g4 = "D"; if(x<=100 && x>70) g5 = "A"; else if(x<=69 && x>50) g5 = "B"; else if(x<=50 && x>40) g5 = "C"; else g5 = "D"; total = a + b + c + d + x; avg = total / 5; if(avg<=100 && avg>70) ag = "A"; else if(avg<=69 && avg>50) ag = "B"; else if(avg<=50 && avg>40) ag = "C"; else ag = "D"; if(la1<=100 && la1>70) lann1 = "A"; else if(la1<=69 && la1>50) lann1 = "B"; else if(la1<=50 && la1>40) lann1 = "C"; else lann1 = "D"; Object Source=e.getSource(); if (e.getSource()==Calculatebutton) { result1.setText ("Your name is "+z+", your ic number is "+y); result2.setText (" your CSC230 grade is " +g1+", CSC231 grade is "+g2+", CSC239 grade is "+g3+", MGT227 grade is "+g4+", and ENL205 grade is "+g5); result3.setText (" your total marks of all subjects is " +total+ " your average mark is " +avg+ " and your average grade is " +ag); Checkbox cb = p.getSelectedCheckbox(); String mode = cb.getLabel(); if(mode.equals("NONE")) result4.setText("you don't have taken LAN subject in this semester"); else if(mode.equals("LAN1001")) result4.setText("you are taking LAN1001 and your grade is "+lann1); else if(mode.equals("LAN1003")) result4.setText("you are taking LAN1003 and your grade is "+lann1); else if(mode.equals("LAN1005")) result4.setText("you are taking LAN1005 and your grade is "+lann1); } } } |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
You need a main method
public stactic void main (str args[]); <--- soemthing like that cant remember, otherwise the program does not no where to start from.
__________________
"Put your hand on a hot stove for a minute, and it seems like an hour. Sit with a pretty girl for an hour, and it seems like a minute. THAT'S relativity." - Albert Einstein |
|
|
|
|
|
#3 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
Or try viewing from AppletViewer.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() ![]() |
Yes. A main function is required.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Oct 2004
Posts: 5
Rep Power: 0
![]() |
In a program like this that acts as your "main" or primary method. You need a statement that denotes a main method like, "public static void main (String []args)"... good luck
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Project extends JApplet implements ActionListener { //INSERT IT HERE public static void main (String [] args) //INSERT IT HERE { CheckboxGroup p = new CheckboxGroup(); |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Sep 2004
Posts: 10
Rep Power: 0
![]() |
still have error leh??
Does anyone have try to copy and execute my coding?? |
|
|
|
|
|
#7 |
|
Newbie
Join Date: Sep 2004
Posts: 10
Rep Power: 0
![]() |
i add
public static void main(String args[]) { //create instance of Frame Project myframe = new Project( ); myframe.addWindowListener( new WindowAdapter( ) { public void windowClosing(WindowEvent e) { System.exit(0); }//end of windowclosing method } ); } but still canot |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Oct 2004
Posts: 5
Rep Power: 0
![]() |
Hmmm, I am a complete java newb and am just taking my first programming class but... are you calling any methods in your programs from other java class programs? If so, make sure that you have them compiled first before trying to compile this beast.
good luck sir |
|
|
|
|
|
#9 |
|
Newbie
Join Date: Sep 2004
Posts: 10
Rep Power: 0
![]() |
no wow,i din call any method
my coding just dun have a main class so i try to add in but still cannot y?? help help urgent |
|
|
|
|
|
#10 |
|
Newbie
Join Date: Oct 2004
Posts: 5
Rep Power: 0
![]() |
what are you using to code in? if you are using an IDE what error message are you recieving? get textpad and compile it in there, then see what error message you get.
I just fought with a java program for 5 hours, it was very frustrating but once it worked it was very rewarding. stay at it, you will get it. public class Project extends JApplet implements ActionListener drop the "extends ...." to the second line, then compile public class Project xtends JApplet implements ActionListener then be sure the file name is Project.java seemed to compile fine for me good luck |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|