2
votes

I am getting this message every time I compile my code, "Usage: PApplet [options] [sketch args] See the Javadoc for PApplet for an explanation." The code I am using was imported from my old computer via flash drive, and it was working fine when on that computer. When I tried to open the file from the src after putting it in my workspace it didn't consider it a project, so I put it in a new processing project. So basically I'm not sure if I installed processing wrong or something wrong in the code but I am getting this error now and it's pretty annoying because I want to work on this old project. Here is the code:

package tests;

import processing.core.PApplet;
import processing.core.PFont;
import processing.core.PImage;
import java.util.Random;

public class test1 extends PApplet {
    PImage background;
    PImage mole;
    PImage mallet1;
    PImage mallet2;

    PFont f;
    public int timer;
    public int startTime;
    public int gameTime;
    public int startGameTime;

    int score = 0;
    Random rnd = new Random();
    boolean mouseP = false;
    int life = 3;

    Mole mole1;
    Mole mole2;
    Mole mole3;
    Mallet mallet;
     enum GameState {
            MENU,
            RUNNING,
            RUNNING2
       }
     static GameState currentState;

    public void setup() {
        size(1000, 800);
        background = loadImage("background.png");
        currentState = GameState.MENU;
        mole = loadImage("mole.png");
        mole1 = new Mole(mole);
        mole2 = new Mole(mole);
        mole3 = new Mole(mole);
        f = createFont("comic.tff",16,true);
        textFont(f,36);
    }

     public void draw() {

            switch(currentState){
            case MENU:
                drawMenu();
                startTime = millis();
                timer = 0;
                life = 3;
                gameTime = millis();
                cursor(CROSS);
                break;
            case RUNNING:
                drawRunning();
                break;
            case RUNNING2:
                drawRunning2();
                gameTime = millis() - startGameTime;

                break;

            }
        }

    public void drawRunning() {
        clear();
        background(background);

        if(timer < 60000){
        mallet2 = loadImage("mallet2.png");
        timer = millis();

        background(background);
        mole1.drawMole();
        mole1.collision(mallet);
        timer = millis() - startTime;
        mallet1 = loadImage("mallet1.png");
        mallet = new Mallet(mallet1, mouseX, mouseY);

        fill(255,255,255);
        text("Time: " + ((60 - timer / 1000)), 850, 50);

        if (mouseP){
            mallet.drawMallet(mallet2, mouseX, mouseY);
        }
        else {
            mallet.drawMallet(mallet1, mouseX, mouseY);
        }
        if(timer > 60000){
            fill(255,255,255);
            text("Game over!" , background.width/2 - 100, background.height/2);

        currentState = GameState.MENU;

        }
        noCursor();
        text("Score: " + score ,25,50);
        }

    }

    public void drawRunning2() {
    clear();
    mallet1 = loadImage("mallet1.png");
    mallet = new Mallet(mallet1, mouseX, mouseY);


    mallet2 = loadImage("mallet2.png");

    background(background);

    timer = millis() - startTime;

    text("Life: " + life ,25,50);

    noCursor();

    text("Time: " + (gameTime / 1000), 825, 50);
    if(life <= 0){
        mole1.dead = true;
        mole2.dead = true;
        mole3.dead = true;
        text("Game over!" , background.width/2 - 100, background.height/2);

        if(mouseP){

            currentState = GameState.MENU;
            timer = 0;
            gameTime = 0;
            startGameTime = millis();
        }

    }

    if (timer < 2000){
        if (!mole1.dead){
            mole1.drawMole();
            mole1.collision(mallet);
        }
        if (!mole3.dead){
            mole3.drawMole();
            mole3.collision(mallet);
        }
        if (!mole2.dead){
            mole2.drawMole();
            mole2.collision(mallet);
        }
        if (mouseP){
            mallet.drawMallet(mallet2, mouseX, mouseY);
        }
        else {
            mallet.drawMallet(mallet1, mouseX, mouseY);
        }
    }
    else {
        startTime = millis();
        if (!mole1.dead || !mole2.dead || !mole3.dead) {
            life --;
        }
        if (life > 0){
            mole1.dead = false;
            mole2.dead = false;
            mole3.dead = false;

            mole1.xPos = rnd.nextInt(925);
            mole1.yPos = rnd.nextInt(725);
            mole3.xPos = rnd.nextInt(925);
            mole3.yPos = rnd.nextInt(725);
            mole2.xPos = rnd.nextInt(925);
            mole2.yPos = rnd.nextInt(725);

            }

        }
    }

    public void drawMenu(){
        clear();
        background(142,22,178);

        fill(165, 119, 249);
        rect(250, 150, 500, 200 );
        fill(255,255,255);
        text("Time Mode", 375, 270);
        fill(165, 119, 249);
        rect(250, 450, 500, 200 );
        fill(255,255,255);
        text("Survival Mode", 375, 570);

    }

            public void mousePressed()
            {
                mouseP = true;

                if( currentState == GameState.MENU && mouseX > 250 && mouseX < 750 && mouseY > 150 && mouseY < 350){
                    currentState = GameState.RUNNING;
                }
                if( currentState == GameState.MENU && mouseX > 250 && mouseX < 750 && mouseY > 450 && mouseY < 650){
                    currentState = GameState.RUNNING2;
            }

            }
                public void mouseReleased()
                {
                mouseP = false;
                }

    public class Mallet{
        PImage mallet1;
        PImage mallet2;
        float xPos1;
        float yPos1;

        public Mallet(PImage mallet1, float xPos1, float yPos1){

            this.mallet1 = mallet1;
            this.xPos1 = xPos1;
            this.yPos1 = yPos1;
        }

        public void drawMallet(PImage mallet1, float xPos1, float yPos1){
            image(mallet1, xPos1 - 40, yPos1 - 60);
        }
    }
    public class Mole{
        PImage Mole;
        float xPos;
        float yPos;
        boolean dead = false;

        public Mole(PImage mole){       
            this.Mole = mole;
            this.xPos = rnd.nextInt(925);
            this.yPos = rnd.nextInt(750);
        }


        public void drawMole(){
            if (dead == true) {
                this.xPos = rnd.nextInt(1000 - mole.width / 2);
                this.yPos = rnd.nextInt(800 - mole.height);
                dead = false;
            }
            image(Mole, xPos, yPos);    
        }   

        public void collision(Mallet m){
            if(
                    mouseP == true &&
            mouseX > xPos && mouseX < xPos + mole.width && mouseY > yPos && mouseY < yPos + mole.height){
                score ++;
                dead = true;
            }
        }
        }
    }
3
there are also 2 errors on the file Description Resource Path Location Type Archive for required library: 'src/tests/library/export.txt' in project 'tests' cannot be read or is not a valid ZIP file tests Build path Build Path Problem The project cannot be built until build path errors are resolved tests Unknown Java ProblemAndrew

3 Answers

4
votes

I recommend getting something smaller working first.

Start over with a new project, and get this working:

public class ProcessingTest extends PApplet{

    @Override
    public void settings() {
        size(200, 200);
    }

    @Override
    public void draw() {
        background(0);
        fill(255, 0, 0);
        ellipse(100, 100, 100, 100);
    }

    public static void main (String... args) {
        ProcessingTest pt = new ProcessingTest();
        PApplet.runSketch(new String[]{"ProcessingTest"}, pt);
    }
}

That will test whether you have the Processing dependencies setup correctly. If you get stuck, then you'll be able to ask a more specific question.

After you get that working, then you can add small pieces of code to the working example until it stops working, which again will allow you to ask a more specific question. It's all about narrowing the problem down: your error probably has nothing to do with the font, so why does your code contain font logic? In other words, please post an MCVE.

If you do get stuck again, try to be more specific about your error: are you sure it happens during compilation, or is it when you try to run? What line is it on? What version of Processing are you using? How are you running your code? (I don't see a main() method?)

You should also try to use proper formatting (indentation) and naming conventions (class names start with upper-case letters, methods and variables with lower-case letters). This will help us read your code and will help you notice bugs.

I'll also say that copying an eclipse project from one computer to another is often more trouble than it's worth. Unless all of your dependencies are in exactly the same place, you're going to have problems. Instead, I'd recommend creating a new project and only copying over the code.

1
votes

I bump into same problem, in Intellij, there is a simple solution for you. You are using package tests in your code. You should add tests.test1 into your Program arguments.

From top-right, go for Edit Condiguration > Program arguments.

0
votes

I copied your code verbatim, and the only addition I had to make, in order to get it to run, was to add the following:

public static void main(String[] args) {
        PApplet.main("test1");
    }

You have to call the object from main()1. Note that I am using Eclipse.

I also had to move the call to size() to settings() as I wasn't using the PDE.

    public void settings() {
        size(1000, 800);
    }

otherwise, in Eclipse, you get this error:

When not using the PDE, size() can only be used inside settings().
Remove the size() method from setup(), and add the following:
public void settings() {
  size(1000, 800);
}
java.lang.IllegalStateException: size() cannot be used here, see https://processing.org/reference/size_.html
    at processing.core.PApplet.insideSettings(PApplet.java:949)
    at processing.core.PApplet.size(PApplet.java:2018)
    at moletest.setup(moletest.java:55)
    at processing.core.PApplet.handleDraw(PApplet.java:2432)
    at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1547)
    at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:313)

Once I had done that then the PApplet ran and displayed the first window perfectly.

However, as some of the resources were missing, I (understandably) got the following errors:

The file "background.png" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
The file "mole.png" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
"comic.tff" is not available, so another font will be used. Use PFont.list() to show available fonts.

So to sum up, your code seems to be fine. However, if you change your compiling environment then some minor changes may be required.


Footnotes

1 See How to write and run processing code in Eclipse? How to make Eclipse a second home for processing?

  1. main(String args[]); is required in Java to say start here. Processing has a pre processor that does this for you, but in Eclipse you have to add it yourself.