We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I get null on line
choseFrame();
PImage f = frame[selecMovie][selecImage];
Can someone help me find the problem? I don't know what it is the solution. Is the problem is how I load images or how I request to display the image. It looks like the image are loading.
java.io.File folder;
int totalPage=64; //number of page
float page=1;
float pageNow; //the last limit
float pageAdd; // time gape in a page
float pageBefor; //the first limit
int numberM;
String [] MovieID; //name of the folder
int [] tFMovieID; //total image in folder
PImage[][] frame;
int numberFrame;
int numberMovie;
int[] x;
int[] y;
int selecImage;
void setup() {
size(840, 640);
smooth();
frameRate(1);
MovieID = new String[3];
MovieID[0] = "tt0062622";// 2001 image 1.png....298.png
MovieID[1] = "tt0074812"; // Logan's Run image 1.png....238.png
MovieID[2] = "tt0119177"; // Gattaca image 1.png....213.png
for (int i=0; i< MovieID.length; i++ ) {
folder = new java.io.File(dataPath(MovieID[i]+"/"));
String[] filenames = folder.list();
numberFrame=filenames.length-1;
frame=new PImage[MovieID.length][numberFrame];
for ( int j = 1; j< numberFrame; j++ )
{
frame[i][j] = loadImage(dataPath(MovieID[i]+"/"+j+".png"));
println(frame[i][j]);
}
}
x= new int[20];
int moreX=0;
for ( int i=0; i<x.length; i++ ) {
x[i]=20+moreX;
moreX=moreX+40;
}
y= new int[12];
int moreY=0;
for ( int i=0; i<y.length; i++ ) {
y[i]=10+moreY;
moreY=moreY+50;
}
}
void draw() {
background(255);
int numXPos= int(random(1, 14));
int numYPos= int(random(1, 9));
int numXImg= int(random(6, 9));
choseFrame(x[numXPos], y[numYPos], x[numXImg]);
}
void choseFrame(float imageX, float imageY, float imageSizeX) {
pageNow= 100*page/totalPage; //the last limit
pageAdd= 100*1/totalPage; // time for a page
pageBefor= pageNow-pageAdd; //the first limit
imageSizeX =imageSizeX-20;
println("chose frame image size X", imageSizeX);
selecImage = round ( random ( numberFrame*(pageBefor/100), numberFrame*(pageNow/100)));
println("chose frame Selectimag ", selecImage);
int selecMovie= int(random(0, MovieID.length));
println("chose frame movie ", selecMovie);
PImage f = frame[selecMovie][selecImage];
println("f imgage ", frame[0][selecImage]);
println("chose frame f ", f);
float imageSizeY= (imageSizeX*f.height)/f.width;
println("X1", imageX, " add ", imageX+imageSizeX);
if (imageX+imageSizeX> 780) {
imageX= imageX- ( (imageX+imageSizeX)-780);
}
println("X2", imageX);
if (imageY+imageSizeY> 560) {
imageY= imageY- ( (imageY+imageSizeY)-560);
}
image(f, imageX, imageY, imageSizeX, imageSizeY);
}
Answers
It is probably caused when
selecImage
has the value 0 (zero) because in line 39 you don't load an image for the [0] element since the loop counter starts at 1I realize I have basic mistakes. I have been suggested by a friend to only load images I need instead of loading all images and chose it randomly. I am looking into that option. Have a page[] that loads 1 to 3 image and from that page[] array the layout will be determined by the number of images inside. Instead of loading all images, choosing the layout and after that piking the image. i willget back at you to let you know how it whent. thanks
i stil try to know whats wrong i have remove more code to go near the problem. still have null pointer Exception
image(frame[0][10], 0, 0);
I see the image loading!
}
You have 2 arrays called
frame
a global one at line 9 and another one local to the setup method in line 24. The local one stores the images but the global one is being used in the draw method.Changes line 24 to
frame = new PImage[numberMovie][numberFrame];
so that we have the global one only.
thanks quark