Hello. I have files that are required for my game, I have added them to the data folder and yet it says they are still missing or inaccessible. I have checked that the names are the same. I don’t understand why it doesn’t work. Please help!
Without any code there is not so much we can do for you…
Try closing and reopening Processing. Sometimes it doesn’t check for new files in your sketch’s data folder until you reopen the sketch.
If that doesn’t help, post the code that opens those files and a picture of the folder that contains them.
Right, my bad.
import ddf.minim.*;
// Variables
// Dev
boolean dmp = false;
// Timer
int savedTime;
int totalTime = 1000;
int playTime;
int playSeconds;
int playMinutes;
// Sound
AudioSnippet success;
AudioSnippet goalSound;
Minim minim;
Minim minim2;
// Images
PImage player;
PImage goal;
// Level
int level = 1;
int groundY = 620;
// Player
int playerX = 80;
int playerY = 580;
int speed = 5;
int hSpeed = 1;
// Goal
int goalX = 1190;
int goalY = 580;
boolean goalSet = false;
// Fonts
PFont pixel;
// Correct Answers
String correct1 = "";
String correct2 = "";
String correct3 = "";
String correct4 = "";
// Text Completion
int introText = 0;
// Code Blocks Options
boolean option1 = false;
boolean option2 = false;
boolean option3 = false;
public static void main(String[] args) {
PApplet.main("defaultChoiceJam");
}
public void playSuccess() {
//success.rewind();
//success.play();
}
public void playGoal() {
//goalSound.rewind();
//goalSound.play();
}
public void mousePressed() {
System.out.println(mouseX + ", " + mouseY);
// Dev Menu
if((mouseX > 10) && (mouseX < 160) && (mouseY > 680) && (mouseY < 720) && (level == 1) && (dmp == false)) {
dmp = true;
level = 2;
}
if((mouseX > 10) && (mouseX < 160) && (mouseY > 680) && (mouseY < 720) && (level == 2) && (dmp == false)) {
dmp = true;
level = 3;
}
if((mouseX > 10) && (mouseX < 160) && (mouseY > 680) && (mouseY < 720) && (level == 3) && (dmp == false)) {
dmp = true;
level = 4;
}
// Other
if((mouseX > 180) && (mouseX < 340) && (mouseY > 680) && (mouseY < 720)) {
introText = 4;
}
}
public void mouseDragged() {
// Level 1
if((mouseX > 450) && (mouseX < 500) && (mouseY > 420) && (mouseY < 450) && (introText == 3)) {
option1 = true;
}
if((option1 == true) && (introText == 3)) {
rect(mouseX, mouseY, 50, 30);
text("=", mouseX+15, mouseY+25);
}
if((mouseX > 510) && (mouseX < 560) && (mouseY > 420) && (mouseY < 450) && (introText == 3)) {
option2 = true;
}
if((option2 == true) && (introText == 3)) {
rect(mouseX, mouseY, 50, 30);
text(";", mouseX+15, mouseY+25);
}
// Level 2
if((mouseX > 450) && (mouseX < 500) && (mouseY > 420) && (mouseY < 450) && (level == 2)) {
option1 = true;
}
if((option1 == true) && (level == 2)) {
rect(mouseX, mouseY, 50, 30);
text("'", mouseX+15, mouseY+25);
}
if((mouseX > 510) && (mouseX < 560) && (mouseY > 420) && (mouseY < 450) && (level == 2)) {
option2 = true;
}
if((option2 == true) && (level == 2)) {
rect(mouseX, mouseY, 50, 30);
text("'", mouseX+15, mouseY+25);
}
if((mouseX > 570) && (mouseX < 620) && (mouseY > 420) && (mouseY < 450) && (level == 2)) {
option3 = true;
}
if((option3 == true) && (level == 2)) {
rect(mouseX, mouseY, 50, 30);
text("}", mouseX+15, mouseY+25);
}
// Level 3
if((mouseX > 510) && (mouseX < 590) && (mouseY > 420) && (mouseY < 450) && (level == 3)) {
option1 = true;
}
if((option1 == true) && (level == 3)) {
rect(mouseX, mouseY, 80, 30);
text("move", mouseX+5, mouseY+25);
}
if((mouseX > 600) && (mouseX < 650) && (mouseY > 420) && (mouseY < 450) && (level == 3)) {
option2 = true;
}
if((option2 == true) && (level == 3)) {
rect(mouseX, mouseY, 50, 30);
text("up", mouseX+15, mouseY+25);
}
if((mouseX > 660) && (mouseX < 710) && (mouseY > 420) && (mouseY < 450) && (level == 3)) {
option3 = true;
}
if((option3 == true) && (level == 3)) {
rect(mouseX, mouseY, 50, 30);
text("3", mouseX+15, mouseY+25);
}
// Level 4
if((mouseX > 910) && (mouseX < 980) && (mouseY > 400) && (mouseY < 430) && (level == 4)) {
option1 = true;
}
if((option1 == true) && (level == 4)) {
rect(mouseX, mouseY, 70, 30);
text("580", mouseX+5, mouseY+20);
}
if((mouseX > 1050) && (mouseX < 1090) && (mouseY > 400) && (mouseY < 430) && (level == 4)) {
option2 = true;
}
if((option2 == true) && (level == 4)) {
rect(mouseX, mouseY, 40, 30);
text(";", mouseX+5, mouseY+20);
}
// Level 5
if((mouseX > 450) && (mouseX < 520) && (mouseY > 420) && (mouseY < 450) && (level == 5)) {
option1 = true;
}
if((option1 == true) && (level == 5)) {
rect(mouseX, mouseY, 70, 30);
text("key", mouseX+10, mouseY+25);
}
if((mouseX > 530) && (mouseX < 580) && (mouseY > 420) && (mouseY < 450) && (level == 5)) {
option2 = true;
}
if((option2 == true) && (level == 5)) {
rect(mouseX, mouseY, 50, 30);
text("=", mouseX+15, mouseY+25);
}
if((mouseX > 590) && (mouseX < 640) && (mouseY > 420) && (mouseY < 450) && (level == 5)) {
option3 = true;
}
if((option3 == true) && (level == 5)) {
rect(mouseX, mouseY, 50, 30);
text(";", mouseX+15, mouseY+25);
}
}
public void mouseReleased() {
// Dev
dmp = false;
// Level 1
if((mouseX > 600) && (mouseX < 640) && (mouseY > 260) && (mouseY < 280) && (introText == 3) && (option1 == true)) {
correct1 = "=";
option1 = false;
playSuccess();
}
if((mouseX > 580) && (mouseX < 630) && (mouseY > 300) && (mouseY < 330) && (introText == 3) && (option2 == true)) {
correct2 = ";";
option2 = false;
playSuccess();
}
// Level 2
if((mouseX > 600) && (mouseX < 640) && (mouseY > 260) && (mouseY < 280) && (level == 2) && (option1 == true)) {
correct1 = "'";
option1 = false;
playSuccess();
}
if((mouseX > 670) && (mouseX < 710) && (mouseY > 260) && (mouseY < 280) && (level == 2) && (option2 == true)) {
correct2 = "'";
option2 = false;
playSuccess();
}
if((mouseX > 450) && (mouseX < 550) && (mouseY > 370) && (mouseY < 390) && (level == 2) && (option3 == true)) {
correct3 = "}";
option3 = false;
playSuccess();
}
// Level 3
if((mouseX > 450) && (mouseX < 550) && (mouseY > 290) && (mouseY < 310) && (level == 3) && (option1 == true)) {
correct1 = " move";
option1 = false;
playSuccess();
}
if((mouseX > 630) && (mouseX < 670) && (mouseY > 310) && (mouseY < 330) && (level == 3) && (option2 == true)) {
correct2 = "up";
option2 = false;
playSuccess();
}
if((mouseX > 560) && (mouseX < 610) && (mouseY > 330) && (mouseY < 340) && (level == 3) && (option3 == true)) {
correct3 = "3";
option3 = false;
playSuccess();
}
// Level 4
if((mouseX > 1060) && (mouseX < 1130) && (mouseY > 340) && (mouseY < 360) && (level == 4) && (option1 == true)) {
correct1 = "580";
option1 = false;
playSuccess();
}
if((mouseX > 1130) && (mouseX < 1170) && (mouseY > 340) && (mouseY < 360) && (level == 4) && (option2 == true)) {
correct2 = ";";
option2 = false;
playSuccess();
}
// Level 5
if((mouseX > 500) && (mouseX < 530) && (mouseY > 260) && (mouseY < 290) && (level == 5) && (option1 == true)) {
correct1 = "key";
option1 = false;
playSuccess();
}
if((mouseX > 560) && (mouseX < 620) && (mouseY > 260) && (mouseY < 290) && (level == 5) && (option2 == true)) {
correct2 = "=";
option2 = false;
playSuccess();
}
if((mouseX > 560) && (mouseX < 590) && (mouseY > 310) && (mouseY < 330) && (level == 5) && (option3 == true)) {
correct3 = ";";
option3 = false;
playSuccess();
}
}
public void keyPressed() {
// Level 1
if((key == 'w' || key == 'a' || key == 's' || key == 'd') && (introText == 0)) {
introText = 1;
}
if((key == ' ') && (introText == 1)) {
introText = 2;
}
if((key == 'd') && (introText == 2)) {
introText = 3;
}
if((key == 'd') && (introText == 4) || (introText == 5)) {
playerX += speed;
}
// Level 2
if((key == 'w') && (correct1 == "'") && (correct2 == "'") && (correct3 == "}") && (level == 2)) {
playerY -= hSpeed;
}
// Level 5
if((key == 'a') && (correct1 == "key") && (correct2 == "=") && (correct3 == ";") && (level == 5)) {
System.out.println("a");
playerX -= speed;
}
if((key == 'w') && (correct1 == "key") && (correct2 == "=") && (correct3 == ";") && (level == 5)) {
playerY -= hSpeed;
}
}
public void setup() {
// Sound
//minim = new Minim(this);
//success = minim.loadSnippet("success.wav");
//minim2 = new Minim(this);
//goalSound = minim2.loadSnippet("goal.wav");
// Timer
savedTime = millis();
playTime = millis();
// PImage
player = loadImage("https://i.imgur.com/zKUx9aO.png");
goal = loadImage("https://i.imgur.com/qhLJ6OV.png");
// PFont
pixel = loadFont("ZXSpectrum-7-48.vlw");
}
public void settings() {
size(1280, 720);
}
public void draw() {
background(206, 206, 206);
fill(0,0,0);
textFont(pixel);
// Play Time
int sPlayTime = millis() - playTime;
// Level 1
// Ground
line(80, 620, 1230, 620);
// Player
image(player, playerX, playerY);
// Goal
image(goal, goalX, goalY);
// Intro Text
switch(introText) {
case 0:
text("Use WASD to move.", 427, 240);
break;
case 1:
text("Oh my, it seems movement isnt working.", 427, 240);
text("(spacebar to continue...)", 427, 260);
break;
case 2:
text("You'll have to fix it!", 427, 240);
text("('d' to continue...)", 427, 260);
break;
}
if(introText == 3) {
noFill();
rect(440, 260, 350, 200);
text("if(key = " + correct1 + " 'd') { moveCharacter" + correct2 + " (right) }", 450, 270, 340, 190);
// = (answer 1)
rect(450, 420, 50, 30);
text("=", 465, 445);
// ; (answer 2)
rect(510, 420, 50, 30);
text(";", 525, 445);
if((correct1 == "=") && (correct2 == ";")) {
background(206);
introText = 4;
}
}
if(introText == 4) {
// Ground
line(80, 620, 1230, 620);
// Player
image(player, playerX, playerY);
// Goal
image(goal, 1190, 580);
// Finish Intro Text
text("You fixed the code! Reach the goal now.", 357, 240);
if((introText == 4) && (playerX+40 >= goalX) && (level == 1)) {
level = 2;
playGoal();
// Defaults
playerX = 80;
playerY = 580;
goalY = 500;
correct1 = "";
correct2 = "";
correct3 = "";
introText = 5;
}
}
/* Level 2 */
if(level == 2) {
background(206);
goalY = 550;
// Ground
line(80, 620, 575, 620);
line(575, 620, 575, 590);
line(575, 590, 1230, 590);
// Player
image(player, playerX, playerY);
// Goal
image(goal, goalX, goalY);
// Code
noFill();
rect(440, 260, 350, 200);
text("if(key == " + correct1 + "w" + correct2 + ") { moveCharacter(up); wait(1); moveChararcter (down); " + correct3, 450, 270, 350, 190);
// ' (answer 1)
rect(450, 420, 50, 30);
text("'", 465, 445);
// ' (answer 2)
rect(510, 420, 50, 30);
text("'", 525, 445);
// } (answer 3)
rect(570, 420, 50, 30);
text("}", 585, 445);
// left (!answer)
rect(630, 420, 80, 30);
text("left", 635, 445);
// s (!answer)
rect(720, 420, 50, 30);
text("s", 735, 445);
if((correct1 == "'") && (correct2 == "'") && (correct3 == "}") && (playerX+40 >= goalX)) {
level = 3;
playGoal();
correct1 = "still";
correct2 = "";
correct3 = "20";
playerX = 80;
playerY = 580;
}
}
/* Level 3 */
if(level == 3) {
background(206);
goalY = 510;
// Ground
line(80, groundY, 575, groundY);
line(575, 620, 575, 550);
line(575, 550, 1230, 550);
// Player
image(player, playerX, playerY);
// Goal
image(goal, goalX, goalY);
// Code
noFill();
rect(440, 260, 350, 200);
text("platform(1, " + correct1 + "); direction( " + correct2 + "); speed(" + correct3 + ");", 450, 270, 350, 190);
// 30 (!answer)
rect(450, 420, 50, 30);
text("30", 455, 445);
// move (answer 1)
rect(510, 420, 80, 30);
text("move", 515, 445);
// up (answer 2)
rect(600, 420, 50, 30);
text("up", 615, 445);
// 3 (answer 3)
rect(660, 420, 50, 30);
text("3", 675, 445);
// d (!answer)
rect(720, 420, 50, 30);
text("d", 735, 445);
// Moving Platform
if((correct1 == " move") && (correct2 == "up") && (correct3 == "3")) {
int passedTime = millis() - savedTime;
if((passedTime > totalTime) && (groundY >= 550)) {
System.out.println("1 second passed");
groundY -= 15;
playerY -= 15;
savedTime = millis();
}
}
if((correct1 == " move") && (correct2 == "up") && (correct3 == "3") && (playerX+40 >= goalX)) {
level = 4;
playGoal();
correct1 = "300";
correct2 = "";
correct3 = "";
playerX = 80;
playerY = 580;
goalY = 300;
goalX = 595;
}
}
/* Level 4 */
if(level == 4) {
background(206);
if(goalSet == false) {
correct1 = "300";
correct2 = "";
goalX = 595;
goalY = 300;
goalSet = true;
}
// Ground
line(80, 620, 1230, 620);
line(297, 340, 891, 340);
// Player
image(player, playerX, playerY);
// Goal
image(goal, goalX, goalY);
// Code
rect(900, 340, 350, 100);
text("goalY = " + correct1 + correct2, 915, 360);
// 580 (answer)
rect(910, 400, 70, 30);
text("580", 915, 420);
// 20 (!answer)
rect(990, 400, 50, 30);
text("20", 995, 420);
// ; (answer)
rect(1050, 400, 50, 30);
text(";", 1055, 420);
if((correct1 == "580") && (correct2 == ";")) {
goalY = 580;
}
if((correct1 == "580") && (correct2 == ";") && (playerX+40 == goalX)) {
level = 5;
playGoal();
playerX = 120;
goalX = 80;
goalY = 500;
correct1 = "";
correct2 = "";
correct3 = "";
}
}
/* Level 5 */
if(level == 5) {
background(206);
// Ground
line(80, 620, 575, 620);
line(575, 620, 575, 590);
line(575, 590, 1230, 590);
line(80, 540, 540, 570);
// Player
image(player, playerX, playerY);
// Goal
image(goal, goalX, goalY);
// Code
noFill();
rect(440, 260, 350, 200);
text("if(" + correct1 + " = " + correct2 + "'a') { moveCharacter (left)" + correct3 + " }", 450, 270, 350, 190);
// key (answer 1)
rect(450, 420, 70, 30);
text("key", 460, 445);
// = (answer 2)
rect(530, 420, 50, 30);
text("=", 545, 445);
// ; (answer 3)
rect(590, 420, 50, 30);
text(";", 605, 445);
if((correct1 == "key") && (correct2 == "=") && (correct3 == ";") && (playerX-40 <= goalX)) {
playGoal();
background(206);
text("Thanks for playing!", width/2, height/2);
// text("Minutes Played: " + , width/2, height/2+50);
text("Seconds Played: " + sPlayTime/1000, width/2, height/2+100);
}
}
}
Hey,
Can you put your whole folder in github for example.
If your have trouble with your file, it would be nice to see how you set them up and actually be able to run the code.
Also do you know which line is causing problem or which file you can’t access ?
Your code is really long, you should try to reduce it so only the part that is not working is written. It will help you figure out what the problem is and more people on this forum will try to help you. Too long code are usually a bit scary to deal with
pixel = loadFont("ZXSpectrum-7-48.vlw");
Is this the troubling line?
Not sure what you are doing there. Remove those lines and try to run your program again. If you insert the main()
function in your code, it is expected you know how Processing works under the hood.
Kf
Hey, forgot all of this happened. A simple restart of my computer fixed it.
How can this problem be handled for situations where you want to load a file that from project resources? I am using Processing 3 with Eclipse and I want to do just that, but it is not working properly. I keep getting this same error message when trying to use this.getClass().getResource("resource path here")
.
@RecursiveCursive What is the error message that you get? When you load the resources, and because you are using Eclipse, then you need to make sure you provide full path to any of the Processing functions. Can you verify the path you are providing is valid? Also, this could be relevant to your issue.
Kf
@kfrajer This is the error message I am getting:
The file "file:/C:/Users/RecursiveCursive/Desktop/Eclipse%20Projects/MyProcessingSketch/bin/net/recursivecursive/mysketch/res/images/icon.png" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
java.lang.NullPointerException
at net.recursivecursive.mysketch.MySketch.settings(MySketch.java:47)
at processing.core.PApplet.handleSettings(PApplet.java:954)
at processing.core.PApplet.runSketch(PApplet.java:10786)
at processing.core.PApplet.main(PApplet.java:10548)
at processing.core.PApplet.main(PApplet.java:10530)
at net.recursivecursive.mysketch.MySketch.main(MySketch.java:40)
I am not sure why this is happening because the path that is referenced in the error is exactly where the image resides. Furthermore, this same code worked with Processing 2 but now that I am trying to port it to 3, I am running in to this issue. Regarding the StackOverflow link you posted, I am not sure what you are suggesting I should do differently. This is what I currently am doing:
loadImage(getClass().getResource("/net/recursivecursive/mysketch/res/images/icon.png").toString())
From that error log above, it looks in this path:
C:/Users/RecursiveCursive/Desktop/Eclipse%20Projects/MyProcessingSketch/bin/net/recursivecursive/mysketch/res/images/icon.png
Are you sure that the %20
in the Eclipse%20Projects
is a part of it?
If you actually have a folder called Eclipse%20Projects on your desktop and this isn’t the problem, then, chances are, your icon.png
file needs administrator rights to access or something. Windows has quite a bit of access management stuff for files too.
And if not, then I guess getClass().getResource(...
function doesn’t like spaces, so it %20
ifies them. In that case, my only suggestion is to rename Eclipse Projects
to eclipseProjects
Java style or something else, without spaces or any other exotic symbols.
@Architector_4 I tried replacing the %20
with a space and that did not work, so I removed the file:/
entry and that worked, but whenever I exported the jar, it was still not working. Would anyone happen to know what changed from Processing 2 to Processing 3 that is causing it to not work with 3 even though it worked with 2?
Maybe you could try exporting with a bunch of debug statements in place? Like, in void draw()
, try putting stuff like:
String path = getClass().getResource("/net/recursivecursive/mysketch/res/images/icon.png").toString();
text(
path+"\n"+
new File(path).getAbsolutePath()+"\n"+
new File(path).exists()
,5,15);
And see what it shows with these statements?
@Architector_4 I see some weird behavior when I do this. getAbsolutePath()
takes the value of file
and sticks it on the end of the path to the root directory of the Eclipse project. Now I am even less sure of what to do.
Maybe new File(path).getCanonicalPath();
could be useful?
Also, may I ask, why you don’t use dataPath("...")
or sketchPath("...")
? I feel like shoving your path into one of these functions and then using their output might prove a useful replacement.
@Architector_4data It seems like using File(path).getCanonicalPath();
works when running the project in Eclipse, but whenever I try to export it to a jar, the same problem that I have been having this entire time arises.
Regarding dataPath("...")
and sketchPath("...")
, the only reference I can find for those comes from Processing 1. I think they have been removed from Processing 3.
dataPath
and sketchPath
, even if undocumented, are still present and working in Processing 3.
If you let it print getCanonicalPath();
on the screen and export to .jar, what does it say? and what do dataPath("")
and sketchPath("")
say?
@Architector_4 @GoToLoop The problem is that I want to load the icon from an image that will be bundled inside the compiled jar as a resource and acquiring resource files is not working. The issue with all of the suggestion that have been provided so far is that they do not play nice with accessing resources. They only seem to work for files that are saved on the disk.