Big errors i got plz help me out illegal type of expression type,

Thread Solved
Reply

Join Date: Jul 2009
Posts: 8
Reputation: karamjeet2004 is an unknown quantity at this point 
Solved Threads: 0
karamjeet2004 karamjeet2004 is offline Offline
Newbie Poster

Big errors i got plz help me out illegal type of expression type,

 
0
  #1
Jul 1st, 2009
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.geom.*;
  4. import java.sql.*;
  5. public class panel extends JFrame implements ActionListener {
  6.  
  7. ResultSet res;
  8. Connection conn;
  9. Statement stat;
  10.  
  11.  
  12. String lang;
  13. JFrame frame = new JFrame("Graphics Button");
  14. lang="abc";
  15. JButton b1;
  16. JLabel l1,l2,l3;
  17. JPanel p,p1,p2,p3,p4;
  18. p.setSize(100,100);
  19. p.setLayout(new GridLayout(3,0));
  20.  
  21. p1=new JPanel();
  22. p2=new JPanel();
  23. p3=new JPanel();
  24. p4=new JPanel();
  25. l1=new JLabel(lang);
  26. l2=new JLabel();
  27. l3=new JLabel();
  28. ImageIcon button=new ImageIcon("magnifier1.jpg");
  29. b1=new JButton();
  30. b1.setIcon(button);
  31. b1.setOpaque(false);
  32. b1.setFocusPainted(false);
  33. b1.setBorderPainted(false);
  34. b1.setContentAreaFilled(false);
  35. b1.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
  36. b1.setBorderPainted(false);
  37. b1.addActionListener(this);
  38. b1.setBackground(Color.green);
  39. //b2=new JButton("cancel");
  40. p1.setBackground(Color.black);
  41. p1.add(l1);
  42. p2.setBackground(Color.green);
  43. p3.setBackground(Color.red);
  44. p4.setBackground(Color.blue);
  45. p.add(p1);
  46. p.add(p2);
  47. p.add(p3);
  48. p4.add(b1);
  49. //p4.add(b2);
  50. frame.add(p,BorderLayout.CENTER);
  51. frame.add(p4,BorderLayout.SOUTH);
  52. frame.pack();
  53. frame.setVisible(true);
  54.  
  55. try
  56. {
  57. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  58. Connection con=DriverManager.getConnection("jdbc:odbc:guru","","");
  59. stat = conn.createStatement();
  60. res = stat.executeQuery("Select * from hotel");
  61. res.next();
  62.  
  63. //con.close();
  64. }
  65. catch(Exception e)
  66. {
  67. e.printStackTrace();
  68. }//end of try
  69.  
  70. public void actionPerformed(ActionEvent e) {
  71. if(e.getSource() == b1) {
  72. try {
  73. res.next();
  74. }
  75. catch(Exception ee) {}//end of try
  76. showRecord(res);
  77. }//end if
  78. }//end action performed
  79. public void showRecord(ResultSet res) {
  80. try {
  81. l1.setText(res.getString(1));
  82. l2.setText(res.getString(2));
  83. }
  84. catch(Exception e) {}//end try
  85.  
  86. }//end of show record
  87. public static void main(String[] args) {
  88.  
  89. panel p=new panel();
  90.  
  91. p.showRecord(res);
  92. }
  93. }//end ma
/* errors:-
C:\>javac panel.java
panel.java:14: <identifier> expected
lang="abc";
^
panel.java:18: <identifier> expected
p.setSize(100,100);
^
panel.java:18: illegal start of type
p.setSize(100,100);
^
panel.java:19: <identifier> expected
p.setLayout(new GridLayout(3,0));
^
panel.java:19: illegal start of type
p.setLayout(new GridLayout(3,0));
^
panel.java:21: <identifier> expected
p1=new JPanel();
^
panel.java:22: <identifier> expected
p2=new JPanel();
^
panel.java:23: <identifier> expected
p3=new JPanel();
^
panel.java:24: <identifier> expected
p4=new JPanel();
^
panel.java:25: <identifier> expected
l1=new JLabel(lang);
^
panel.java:26: <identifier> expected
l2=new JLabel();
^
panel.java:27: <identifier> expected
l3=new JLabel();
^
panel.java:29: <identifier> expected
b1=new JButton();
^
panel.java:30: <identifier> expected
b1.setIcon(button);
^
panel.java:30: <identifier> expected
b1.setIcon(button);
^
panel.java:31: <identifier> expected
b1.setOpaque(false);
^
panel.java:31: illegal start of type
b1.setOpaque(false);
^
panel.java:32: <identifier> expected
b1.setFocusPainted(false);
^
panel.java:32: illegal start of type
b1.setFocusPainted(false);
^
panel.java:33: <identifier> expected
b1.setBorderPainted(false);
^
panel.java:33: illegal start of type
b1.setBorderPainted(false);
^
panel.java:34: <identifier> expected
b1.setContentAreaFilled(false);
^
panel.java:34: illegal start of type
b1.setContentAreaFilled(false);
^
panel.java:35: <identifier> expected
b1.setBorder(BorderFactory.createEmptyBord
^
panel.java:35: <identifier> expected
b1.setBorder(BorderFactory.createEmptyBord

panel.java:36: <identifier> expected
b1.setBorderPainted(false);
^
panel.java:36: illegal start of type
b1.setBorderPainted(false);
^
panel.java:37: <identifier> expected
b1.addActionListener(this);
^
panel.java:37: illegal start of type
b1.addActionListener(this);
^
panel.java:38: <identifier> expected
b1.setBackground(Color.green);
^
panel.java:38: <identifier> expected
b1.setBackground(Color.green);
^
panel.java:40: <identifier> expected
p1.setBackground(Color.black);
^
panel.java:40: <identifier> expected
p1.setBackground(Color.black);
^
panel.java:41: <identifier> expected
p1.add(l1);
^
panel.java:41: <identifier> expected
p1.add(l1);
^
panel.java:42: <identifier> expected
p2.setBackground(Color.green);
^
panel.java:42: <identifier> expected
p2.setBackground(Color.green);
^
panel.java:43: <identifier> expected
p3.setBackground(Color.red);
^
panel.java:43: <identifier> expected
p3.setBackground(Color.red);
^
panel.java:44: <identifier> expected
p4.setBackground(Color.blue);
^
panel.java:44: <identifier> expected
p4.setBackground(Color.blue);
^
panel.java:45: <identifier> expected
p.add(p1);
^
panel.java:45: <identifier> expected
p.add(p1);
^
panel.java:46: <identifier> expected
p.add(p2);
^
panel.java:46: <identifier> expected
p.add(p2);
^
panel.java:47: <identifier> expected
p.add(p3);
^
panel.java:47: <identifier> expected
p.add(p3);
^
panel.java:48: <identifier> expected
p4.add(b1);
^
panel.java:48: <identifier> expected
p4.add(b1);
^
panel.java:50: <identifier> expected
frame.add(p,BorderLayout.CENTER);
^
panel.java:50: <identifier> expected
frame.add(p,BorderLayout.CENTER);
^
panel.java:50: <identifier> expected
frame.add(p,BorderLayout.CENTER);
^
panel.java:51: <identifier> expected
frame.add(p4,BorderLayout.SOUTH);
^
panel.java:51: <identifier> expected
frame.add(p4,BorderLayout.SOUTH);
^
panel.java:51: <identifier> expected
frame.add(p4,BorderLayout.SOUTH);
^
panel.java:52: <identifier> expected
frame.pack();
^
panel.java:53: <identifier> expected
frame.setVisible(true);
^
panel.java:53: illegal start of type
frame.setVisible(true);
^
panel.java:55: illegal start of type
try
^
panel.java:65: illegal start of type
catch(Exception e)
^
panel.java:65: ';' expected
catch(Exception e)
^
61 errors
*/
Last edited by Tekmaven; Jul 2nd, 2009 at 5:29 pm. Reason: Code Tags
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,532
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 191
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: Big errors i got plz help me out illegal type of expression type,

 
0
  #2
Jul 1st, 2009
Yes. Because you have no main method - you need to put any code (other than variable declarations) inside methods. The main method is the method that runs when you first start your program, *edit*


Oops, nevermind - I see that you do have a main method. For statements like String lang, then lang = "abc", you would need to initially just say String lang = "abc"; . . and what I said about only having variable declarations still stands. lang = "abc" is an assignment statement, and thus, isn't allowed unless you do it inside of a method.
Last edited by BestJewSinceJC; Jul 1st, 2009 at 10:30 pm.
I am so hungry. :(
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,532
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 191
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: Big errors i got plz help me out illegal type of expression type,

 
0
  #3
Jul 1st, 2009
edit, sorry guys. Combined the two posts.
Last edited by BestJewSinceJC; Jul 1st, 2009 at 10:30 pm.
I am so hungry. :(
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 8
Reputation: karamjeet2004 is an unknown quantity at this point 
Solved Threads: 0
karamjeet2004 karamjeet2004 is offline Offline
Newbie Poster

Re: Big errors i got plz help me out illegal type of expression type,

 
0
  #4
Jul 2nd, 2009
I am not satisfied with this answer
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 8
Reputation: karamjeet2004 is an unknown quantity at this point 
Solved Threads: 0
karamjeet2004 karamjeet2004 is offline Offline
Newbie Poster

Re: Big errors i got plz help me out illegal type of expression type,

 
0
  #5
Jul 2nd, 2009
It gives me errors like previous one
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 965
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 145
JamesCherrill JamesCherrill is offline Offline
Posting Shark

Re: Big errors i got plz help me out illegal type of expression type,

 
0
  #6
Jul 2nd, 2009
Satisfied or not, he's right. Everything except variable declarations have to be inside a method. Post your latest code, with code=java tags.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 8
Reputation: karamjeet2004 is an unknown quantity at this point 
Solved Threads: 0
karamjeet2004 karamjeet2004 is offline Offline
Newbie Poster

Re: Big errors i got plz help me out illegal type of expression type,

 
0
  #7
Jul 2nd, 2009
Guys i changed the code now i get 3 errors plz HLP me out errors are after the code
//code
  1. /*<applet code=panel.class height=300 width=500></applet>*/
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.awt.geom.*;
  5. import java.sql.*;
  6. import java.awt.event.*;
  7. import java.net.*;
  8. public class panel extends JApplet implements ActionListener{
  9. ResultSet res;
  10. Connection con;
  11. Statement stat;
  12. JFrame frame;
  13. JButton b1;
  14. JLabel l1,l2,l3;
  15. JPanel p,p1,p2,p3,p4;
  16. ImageIcon button;
  17. public void init(){
  18.  
  19. p=new JPanel();
  20. p1=new JPanel();
  21. p2=new JPanel();
  22. p3=new JPanel();
  23. p4=new JPanel();
  24. l1=new JLabel();
  25. l2=new JLabel();
  26. l3=new JLabel();
  27. b1=new JButton();
  28. frame = new JFrame("Graphics Button");
  29. button=new ImageIcon("magnifier1.jpg");
  30. p.setSize(100,100);
  31. p.setLayout(new GridLayout(3,0));
  32. p1.setBackground(Color.black);
  33. p1.add(l1);
  34. p2.setBackground(Color.green);
  35. p3.setBackground(Color.red);
  36. p4.setBackground(Color.blue);
  37. p.add(p1);
  38. p.add(p2);
  39. p.add(p3);
  40. p4.add(b1);
  41. b1.setIcon(button);
  42. b1.setOpaque(false);
  43. b1.setFocusPainted(false);
  44. b1.setBorderPainted(false);
  45. b1.setContentAreaFilled(false);
  46. b1.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
  47. b1.setBorderPainted(false);
  48. b1.addActionListener(this);
  49. frame.add(p,BorderLayout.CENTER);
  50. frame.add(p4,BorderLayout.SOUTH);
  51. frame.pack();
  52. frame.setVisible(true);
  53. }//end init
  54. try
  55. {
  56. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  57. con=DriverManager.getConnection("jdbc:odbc:guru","","");
  58. try{
  59.  
  60. stat = conn.createStatement();
  61. res = stat.executeQuery("Select * from granth");
  62. res.next();
  63.  
  64. //con.close();
  65. }
  66. catch(Exception e){
  67. e.printStackTrace();
  68. }
  69. }
  70. catch(Exception e){
  71. e.printStackTrace();
  72. }//end of try
  73. public void actionPerformed(ActionEvent e) {
  74. if(e.getSource() == b1) {
  75. try {
  76. res.next();
  77. }
  78. catch(Exception ee) {}//end of try
  79. showRecord(res);
  80. }//end if
  81. }//end action performed
  82. public void showRecord(ResultSet res) {
  83. try {
  84. l1.setText(res.getString(1));
  85. l2.setText(res.getString(2));
  86. }
  87. catch(Exception e) {}//end try
  88.  
  89. }//end of show record
  90. }
/*errors
C:\Documents and Settings\Desktop>javac panel.java
panel.java:54: illegal start of type
try
^
panel.java:70: illegal start of type
catch(Exception e){
^
panel.java:70: ';' expected
catch(Exception e){
^
3 errors
*/
Last edited by Tekmaven; Jul 2nd, 2009 at 5:32 pm. Reason: Code Tags
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 965
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 145
JamesCherrill JamesCherrill is offline Offline
Posting Shark

Re: Big errors i got plz help me out illegal type of expression type,

 
0
  #8
Jul 2nd, 2009
Everything except variable declarations still have to be inside a method. Indent your code so you can see where methods and classes end. Your errors start immediately after the end of the init method because the following code isn't in a method.
This would have been obvious to you with proper indentation and code tags.
Last edited by JamesCherrill; Jul 2nd, 2009 at 8:51 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 965
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 145
JamesCherrill JamesCherrill is offline Offline
Posting Shark

Re: Big errors i got plz help me out illegal type of expression type,

 
0
  #9
Jul 2nd, 2009
ps: If you have code that looks like this:
  1. catch(Exception ee) {}
then what you are saying is: "if my code goes wrong I do not want to know why or where it happened. Please just stop executing and give me no help at all".
Try replacing all those with
  1. catch(Exception ee) {
  2. ee.printStackTrace();
  3. }
so you know what's happening.
Last edited by JamesCherrill; Jul 2nd, 2009 at 9:06 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 8
Reputation: karamjeet2004 is an unknown quantity at this point 
Solved Threads: 0
karamjeet2004 karamjeet2004 is offline Offline
Newbie Poster

Re: Big errors i got plz help me out illegal type of expression type,

 
0
  #10
Jul 2nd, 2009
thnks my code is now running
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC