Compiler Error J0031

Invalid escape character

The compiler detected the use of an invalid escape character. This error usually occurs when a syntactical error is found in a Unicode escape sequence. The error can also occur if you use a "\" character in a string assignment.

The following example illustrates this error:

public class Simple {
   
   int i = \u032; 
   // error: Unicode uses 4 hex digits
   int x = \u0032;
   //correct assignment of a Unicode escape sequence
   
}

The following example illustrates the error being caused by assigning the "\" character improperly to a string:

public class Simple{
   
   public String str = "C:\Windows\Desktop";
   //error: invalid assignment of the '\' character to a string
   //To assign it correctly use the '\\' character assignment
}