Umlaute is an Invalid character constant?

I am checking if there are some Umlaute in my text. The error message is “Invalid character constant”

```
if (text.charAt(0) == 'ä') println("Hallo");
```

The same happens IMHO with every char above #127. This only happens in Processing. In pure java it works as it should.

Mit herzlichen Grüßen

Uli

Hello @u.strautz,

Welcome!

It works with Processing 4.4.10 on W10:

Also works with Processing 4.5.2 on W10.

Can you please provide some details:

  • Processing version
  • Operating system
  • An MCVE for us to try.
    This can help narrow it down.
    Sometimes it is the renderer or something else in the code.

More on MCVE here:
Guidelines—Asking Questions

:)

I use W11 & Processing 4.5.2

The IA said I should check the coding. I did and it is UTF-8 w/o BOM

If the only Tab is…

void setup() {
size(400, 400);
}

void draw() {
String text = “äbc”;
if (text.charAt(0)== ‘ä’) println(“Hallo”);
}

it works just fine.
The trouble begins, when I have a second tab (StringInt.java). Now the error pops up.

public class StringInt {

} // end of class StringInt 

So it has something to do with regular java classes. I need them to experience private procedures and variables in class. (encapsulation)

Gruß, Uli

1 Like

Hello,

I only get the error if there is a java extension even if it empty.

Workaround:

size(200, 100);

char c0 = "ä".charAt(0); // This is your umlaute character
println(c0);

char c1 = "Ω".charAt(0); 
println(c1);

String text = "äbc";
if (text.charAt(0) == c0) println("Hallo");

textSize(24);
fill(0);
text(c0 + " " + c1, 20, 50);

Practical example:

String text = "ä ö ü Ä Ö Ü ß";
// Either of these work:
//char um = text.charAt(0);     //umlaute
char um = "ä".charAt(0);      //umlaute  
  
String s0 = "Äpfel, Öl und Käse gehören zu süßen und würzigen Speisen.";
String s1 = "ä ö ü Ä Ö Ü ß sind die deutschen Sonderzeichen.";

void setup()
{
  for(int i=0; i<s0.length(); i++)
   {
   if (s0.charAt(i) == um) 
     println("Index", i, "contains", um);
   } 
}

There may be something in here to explain:
processing4/java/src/processing/mode/java/JavaBuild.java at main · processing/processing4 · GitHub

Note:
I deleted a previous post.
I was remaining tabs (with and without the java extension) before and did NOT restart the PDE and was under the impression I had a solution. I did not.

Live and learn.

:)

Thanks for trying, the workaround works but is a bit ugly.

BTW I did never mention: It is only a processing warning so it compiles smoothly. The java compiler is not the problem.

Thanks again, Uli

1 Like

It is not a working solution.
Having the java extension also appears to suppress other warnings.

This topic and investigation may help shed some light on this at some point.

I did not find a related issue here:

Did not do an exhaustive search.

@stefterv Any idea about this?

:)

It is not a working solution.
Having the java extension also appears to suppress other warnings.

This topic and investigation may help shed some light on this at some point.

I did not find a related issue here:

Did not do an exhaustive search.

This worked:

Use UTF-8 code pages in Windows apps - Windows apps | Microsoft Learn
Link has a box that tells how to set this for Windows 10 or 11.

Once I selected this I did not see the “Invalid character constant” errors:

As always… proceed with caution.
It worked on my Windows 10 PC.

:)