problem on Explay Hit Android 4.2.2

edited May 2016 in Android Mode

Hello, I'm a beginner at Processing. Today I tried to make an easy application on Android (just to display some text and add a picture). But I got an error

So, here's my code:

PFont f;
PImage img;

void setup() {
  size(displayWidth, displayHeight);

  img = loadImage("korona42.png");
}

void draw() {
  background(255);
  f = loadFont("Kristen-ITC.ttf");
  textFont(f, displayWidth/18);
  fill(0);
  text("KÖNIG  DEUTSCH", displayWidth/2-displayWidth/18/1.5*7, displayHeight/2);
  image(img, width/4.2, height*8.7/24, displayWidth/18, displayWidth/18/1.5);
}

Application doesn't work and that was written:

_debug:
java.lang.NullPointerException: in == null
    at libcore.io.Streams.readFully(Streams.java:74)
    at java.io.DataInputStream.readInt(DataInputStream.java:124)
    at processing.core.PFont.<init>(Unknown Source)
    at processing.core.PApplet.loadFont(Unknown Source)
    at processing.test.logo.LOGO.draw(LOGO.java:30)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
    at processing.core.PApplet.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:838)
java.lang.RuntimeException: Could not load font Kristen-ITC.ttf. Make sure that the font has been copied to the data folder of your sketch.
    at processing.core.PApplet.die(Unknown Source)
    at processing.core.PApplet.die(Unknown Source)
    at processing.core.PApplet.loadFont(Unknown Source)
    at processing.test.logo.LOGO.draw(LOGO.java:30)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
    at processing.core.PApplet.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:838)
FATAL EXCEPTION: Animation Thread
java.lang.RuntimeException: Could not load font Kristen-ITC.ttf. Make sure that the font has been copied to the data folder of your sketch.
    at processing.core.PApplet.die(Unknown Source)
    at processing.core.PApplet.die(Unknown Source)
    at processing.core.PApplet.loadFont(Unknown Source)
    at processing.test.logo.LOGO.draw(LOGO.java:30)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
    at processing.core.PApplet.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:838)_

Where's my mistake?? Help please! I don't understand! [-O< :-S

Tagged:

Answers

  • Answer ✓

    Take a look at this line:

    java.lang.RuntimeException: Could not load font Kristen-ITC.ttf. Make sure that the font has been copied to the data folder of your sketch.
    

    Is the font in the data folder?

    You can try using createFont() instead:

    f = loadFont("Arial", displayWidth/18);
    

    The problem here is that you can't use your custom font...

    Note: I would strongly advise that you perform the loading of your font in setup(), the same way that you load the image.

  • Thank you!!!

Sign In or Register to comment.