Badly formed character (expecting quote, got I) ~

2019-08-16 21:11发布

问题:

I hope someone can help me with my problem. I'm trying to make a simple visualization to show how soccer teams either moved up or down in the FIFA rankings for 2012. To that I have created and loaded 17 images to my sketch which I want to move based on a button event. Below is my code:

//Setting up the images that will go into the sketch

PImage img1;
PImage img2;
PImage img3;
PImage img4;
PImage img5;
PImage img6;
PImage img7;
PImage img8;
PImage img9;
PImage img10;
PImage img11;
PImage img12;
PImage img13;
PImage img14;
PImage img15;
PImage img16;
PImage img17;

//loading the images from the file
void setup() {
  size(600, 1100)
  img1 = loadImage('Click.png');
  img2 = loadImage('Team_xxxxx.png');
  img3 = loadImage('Team_xxxxxx.png');
  img4 = loadImage('Team_xxxxxx.png');
  img5 = loadImage('Team_xxxxxxx.png');
  img6 = loadImage('Team_xxxxx.png');
  img7 = loadImage('Team_xxxxxx.png');
  img8 = loadImage('Team_xxxxxxx.png');
  img9 = loadImage('Team_xxxxxx.png');
  img10 = loadImage('Team_xxxxxx.png');
  img11 = loadImage('Team_xxxxx.png');
  img12 = loadImage('Team_xxxxx.png');
  img13 = loadImage('Team_xxxxx.png');
  img14 = loadImage('Team_xxxxxx.png');
  img15 = loadImage('Team_xxxxx.png');
  img16 = loadImage('Team_xxxxx.png');
  img17 = loadImage('Team_xxxxxx.png');
}

//Drawing the images into the sketch
void draw() {
  image(img1, 400, 100);
  image(img2, 100, 250);
  image(img3, 100, 300);
  image(img4, 100, 350);
  image(img5, 100, 400);
  image(img6, 100, 450);
  image(img7, 100, 500);
  image(img8, 100, 550);
  image(img9, 100, 600);
  image(img10, 100, 650);
  image(img11, 100, 700);
  image(img12, 100, 750);
  image(img13, 100, 800);
  image(img14, 100, 850);
  image(img15, 100, 900);
  image(img16, 100, 950);
  image(img17, 100, 1000);
}

I keep getting this error message: Badly formed character (expecting quote, got I). And below is the output in the console:

 processing.app.SketchException: Badly formed character constant (expecting quote, got l)
        at processing.mode.java.preproc.PdePreprocessor.checkForUnterminatedMultilineComment(PdePreprocessor.java:478)
        at processing.mode.java.preproc.PdePreprocessor.write(PdePreprocessor.java:515)
        at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:270)
        at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:185)
        at processing.mode.java.JavaBuild.build(JavaBuild.java:144)
        at processing.mode.java.JavaBuild.build(JavaBuild.java:123)
        at processing.mode.java.JavaMode.handleRun(JavaMode.java:114)
        at processing.mode.java.JavaEditor$19.run(JavaEditor.java:474)
        at java.lang.Thread.run(Thread.java:680)

I'm using Processing 2.0B7 on a Macbook Pro running on OS X.

回答1:

The error probably comes from

img1 = loadImage('Click.png');

specifically the 'Cl bit. Character constants consist of a single quote ('), some character, and another single quote (').
What you have is a single quote ('), a C, then an l.

Since you seem to want a string constant instead, try double quotes:

img1 = loadImage("Click.png");