What is the Java Compiler Error ?
error: ‘(‘ or ‘[‘ expected
Reason for the Error
You will likely get this error when you have missed [] when declaring an array in Java. For example, the below code snippet results in the ‘(‘ or ‘[‘ expected error in Java.
public class Main { public static void main(String[] args) { String[] arry = new String {"item1", "item2" }; } }
There are other reasons why you might this error too. For example, you have either missed ( or [ methos when declaring or calling a method or when calling and returning value form the array index.
How to Fix the Error?
You can fix the error by including the missing ‘(‘ or ‘[‘ as shown in the below code snippet.
public class Main { public static void main(String[] args) { String[] arry = new String [] {"item1", "item2" }; } }
Amazing article. Your blog helped me to improve myself in many ways thanks for sharing this kind of wonderful informative blogs in live. I have bookmarked more article from this website. Such a nice blog you are providing !