• Register
1 vote
127 views

Problem:

I've got a simple code of java. I am being a failure to compile my program. It throws back an unknown error says, missing '}' or illegal start of expression. Here is my code snippet

public class MyClass {
  public static void main(String[] args) {
    count();  
  public static int count() {
    return 0;
  }
}

Any idea? An advance thanks for your solution.

12 7 7
15,250 points

Please log in or register to answer this question.

2 Answers

1 vote
 
Best answer

Solution:

This a compile-time error. The java compiler javac read your program from top to bottom and left to right once you hit the compile button. It throws back the illegal start of expression error once it finds something inappropriate at the start of an expression.

Let’s figure the problems in your code step by step. First of all, you haven’t closed the brace of your main method. As soon as you close the brace first problem is resolved. Now, coming to the second problem, you can’t add another public method inside your main method in java. You can only have public methods outside of your main method.

Always leave a print() function inside your main method to understand whether your program is running or not! The whole program could have been like this:

public class MyClass {
  public static void main(String[] args) {
    count();
    System.out.println("Program is running!");
  }
  public static int count() {
      return 0;
  }
}

Keep exploring. Thanks.

13 9 6
94,260 points
0 votes

This error is a compile time error when the compiler encounters an inappropriate statement in the source code. This error can be encountered in various scenarios . Illegal start of expression can be encountered in various scenarios. The following are the most common errors:

  • Missing an opening or closing curly bracket for a code block
  • Declaring a function inside another function
  • Using an access specifier with a function's local variable
  • String Character Without Double Quote

To debug this error, try looking at the lines preceding the error message for missing brackets, curly braces or semicolons and check the syntax.

2
140 points

Related questions

0 votes
0 answers 5 views
5 views
Problem: Can anyone help me what is illegal start of expression?
asked Mar 26 ashik 14.6k points
0 votes
0 answers 4 views
4 views asked Mar 26 ashik 14.6k points
0 votes
1 answer 2 views
2 views
Problem: Your help would mean a lot to me. Thank you!
asked 2 days ago salim1 60.6k points
0 votes
1 answer 7 views
7 views
Problem: I need help in resolving this problem: The program can't start because api-ms-win-crt-runtime-l1-1-0.dll is missing from your computer fix?
asked Mar 30 tuhin1 48.9k points
0 votes
1 answer 6 views
6 views
Problem: I've just started using Visual Studio (I got VS 2012 from dreamspark, and it hasn't been long since I've started using Windows again) and I'm having some trouble. pPlease help?
asked Apr 6 Sana8989 8.9k points
0 votes
1 answer 15 views
15 views
When I'm building the project, it's good, but impossible to run it. What am I doing wrong?
asked Dec 15, 2020 TeamScript 13.5k points
1 vote
1 answer 6 views
6 views
Problem : I can't find a missing assignment operator > Syntax error, insert "AssignmentOperator Expression" to complete Expression
asked 5 days ago Abik Dey 4k points
0 votes
1 answer 3 views
3 views
Problem: I had asked a question about this earlier, but it didn't get answered right and led nowhere. So I've clarified few details on the problem and I would really like to hear your ideas on how could I fix this or what should I try. I have Java 1.6.0 ... almost completely with the 1.6.0.26 java.security file. There are no additional providers in the first one. * The previous question is here.
asked 4 days ago Yeamin 21.4k points
0 votes
1 answer 2 views
2 views
Problem: I had asked a question about this earlier, but it didn't get answered right and led nowhere. So I've clarified few details on the problem and I would really like to hear your ideas on how could I fix this or what should I try. I have Java 1.6.0 ... almost completely with the 1.6.0.26 java.security file. There are no additional providers in the first one. * The previous question is here.
asked 4 days ago anika11 32k points