java: unclosed string literal [Error]


If you try to run Java code in IntelliJ IDEA, the IDE for Java Programming, you may get "java: unclosed string literal" error if having an incorrectly defined String. A String Class object in Java must be enclosed in double quotes, if you miss them you will get this error.

package com.java.code2care.example;

public class Main {

    public static void main(String[] args) {

        System.out.println("Hello World!);

    }
}
Output:

/Main.java:9:28
java: unclosed string literal

As you can see the String Hello World! is missing a closing double quote, if you add it the error will be resolved. If you hover over the String in IntelliJ you will see the error - Illegal line end in string literal

java: unclosed string literal
java: unclosed string literal


Have Questions? Post them here!



Recent Posts:




Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.