APDE and switch(String) compile errors


#1

Hello, I’m a begginer with APDE and processing, and meed some help.

I create this sketch on Processing 3.4 in Windows : no PB, it’s juste a sample.

//-------------------------
String state = “none”;
int w, h;
void setup() {
state = “setup”;
w = 100;
h = 100;
}

void draw() {
switch(state) {
case “none”: /* do nothing */ break;
case “setup”: state = “draw”; break;
case “draw”: line(0, 0, random(0, w), random(0, h)); break;
}
}
//-------------------------

But when I try to run it under my Phone with APDE verrsion 0.5.0 I have many compiles errors.
Ok managing a state in a string is not a good idea, this is just a sample to have the compile error.

Initializing build sequence…

Deleted old build folder

Injected log broadcaster

Detected architecture armeabi-v7a

Packaging resources with AAPT…

Compiling with ECJ…


  1. ERROR in /data/data/com.calsignlabs.apde/app_build/src/processing/test/switch/switch.java (at line 1)

package processing.test.switch;

                    ^^^^^^

Syntax error on token “switch”, Identifier expected


  1. ERROR in /data/data/com.calsignlabs.apde/app_build/src/processing/test/switch/switch.java (at line 17)

public class switch extends PApplet {

         ^^^^^^

Syntax error on token “switch”, Identifier expected



  1. ERROR in /data/data/com.calsignlabs.apde/app_build/src/processing/test/switch/MainActivity.java (at line 1)

package processing.test.switch;

                    ^^^^^^

Syntax error on token “switch”, Identifier expected


  1. ERROR in /data/data/com.calsignlabs.apde/app_build/src/processing/test/switch/MainActivity.java (at line 23)

sketch = new switch();

         ^^^^^^

Syntax error on token “switch”, invalid ClassType



  1. ERROR in /data/data/com.calsignlabs.apde/app_build/src/processing/test/switch/APDEInternalLogBroadcasterUtil.java (at line 1)

package processing.test.switch;

                    ^^^^^^

Syntax error on token “switch”, Identifier expected



  1. ERROR in /data/data/com.calsignlabs.apde/app_build/gen/processing/test/switch/R.java (at line 8)

package processing.test.switch;

                    ^^^^^^

Syntax error on token “switch”, Identifier expected


6 problems (6 errors)


#2

The problem is that you have named your sketch switch, which is a keyword in Processing/Java. The compiler errors are with the code that Android mode generates around your sketch. You need to rename your sketch something else, from menu > “Rename Sketch”.