• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error in frame based application

 
chandan kuchipudi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all .....i've got a problem whlie executing this frame based application ....please resolve it ...

//CheckDemo.java

import java.awt.*;
import java.awt.event.*;

class CheckBox extends Frame
{
Checkbox cb1,cb2,cb3;
Label l1;

Check()

{
setTitle("CHECKBOX DEMO");
setSize(300,300);
FlowLayout fl=new FlowLayout();
setLayout(fl);
// create the components
cb1=new Checkbox("java");
cb2=new Checkbox(".NET");
cb3=new Checkbox("CLOUD COMPUTING");
l1=new Label("YOUR SELECTED COURSE");


//ADD COMPONENTS TO CONTAINER

add(cb1);add(cb2);add(cb3);add(l1);

//registration process

Sathya so=new Sathya();
cb1.addItemListener(so);
cb2.addItemListener(so);
cb3.addItemListener(so);

setVisible (true);
}//check()

class Sathya implements ItemListener
{
public void itemStateChanged(ItemEvent ie)
{
if (ie.getSource()==cb1)

{
if(cb1.getState())
{
l1.setText("your selected course:"+cb1.getLabel());
}
if(cb2.getState())
{
l1.setText("your selected course:"+cb2.getLabel());
}
if(cb3.getState())
{
l1.setText("your selected course:"+cb3.getLabel());
}
else
{
l1.setText("your selected course=none");
}//else
}//isc

}//sathya
}//check
class CheckDemo1
{
public static void main (String [] args)
{
Check co= new Check();
}
}
}


it is showing that

java 11:error invalid method declaration; return type required Check()


please look into that once.


 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at where the error is being reported.
If you were trying to create a constructor for the CheckBox class then the constructor must be named the same as the class name. You have the class name as CheckBox but the constructor is named Check.

P.S Use code tags when posting code.
 
chandan kuchipudi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thankyou ...i've changed the constructor ...

but it is showing the error after this


line no 67: error: illegal static declaration in inner class Check CheckDemo1.java

public static void main (String []args)

modifier 'static' is only allowed in constant variable declarations
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error says: static methods can only be declared in a static or top level type.

So either make the class with the main method static or move the main method into a top level class.
You should try to read and understand what the error messages are telling you. They usually contain vital hints.

 
Darryl Burke
Bartender
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved from Applets
 
Gaurangkumar Khalasi
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chandan kc wrote:line no 67: error: illegal static declaration in inner class Check CheckDemo1.java
public static void main (String []args)
modifier 'static' is only allowed in constant variable declarations


Because inner class do not have static declaration, only Static nested class can have.

And Please use the UseCodeTags.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic