I am looking to load and view an arbitrarily large image by breaking it up into 1000x1000 blocks and loading the ones immediately around a PVector "camera." The problem is I need to be able to get rid of images from the memory that are no longer in use. Are loaded files handled automatically by the garbage collector, or is there any additional memory handling that I need to use?
I am working on a game that retrieves information from text files to construct a variety of in game objects. The architecture of my data folder looks like this:
when called, the following error occurs and stops the sketch:
The file "ships/Interceptor.txt" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
Exception in thread "main" java.lang.RuntimeException: java.lang.NullPointerException
at processing.core.PApplet.runSketch(PApplet.java:9660)
at processing.core.PApplet.main(PApplet.java:9469)
Caused by: java.lang.NullPointerException
at Laser_Ships_2_0$Ship.<init>(Laser_Ships_2_0.java:184)
at Laser_Ships_2_0.loadtest(Laser_Ships_2_0.java:312)
at Laser_Ships_2_0$_Game.<init>(Laser_Ships_2_0.java:52)
at Laser_Ships_2_0.<init>(Laser_Ships_2_0.java:87)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at processing.core.PApplet.runSketch(PApplet.java:9658)
... 1 more
Trouble shooting steps I've taken so far,
*Made sure all files existed and had correct names and extensions.
*Ran test sketches to confirm I know how to use loadStrings() and that it's working.
*Made sure there are no properties of the file making it inaccessible to the sketch.
*Changed the encoding of the .txt file to UTF-8
*Restarted processing, restarted computer.
Note, I have extremely limited internet access.
Thank you for your help! :)
**additional note, when all file references are commented out of the code a null pointer exception occurs without any information on where it occurred. That did not happen previous to the files or file reading code being added.
I wrote this recursive function to calculate the nth term of the Fibonacci sequence:
long f(long n){
if(n <= 0){ return n * -1; }
return f(n - 1) + f(n - 2);
}
The problem is it runs extremely slow, with inputs over about 40 taking minutes and the time to complete increasing directly with the size of the answer. I believe it is because the function can only add by 0 or 1 each time it reaches its base case (n == 0 or n == -1).
Does someone have a suggestion on how to dramatically speed up the function while remaining concise?
where the angle is set to the frame times 1 full rotation divided by 60 times the number of frames in 1 minute, so that 1 full rotation is made each hour.
The clock does not show the correct minute time. The -1353555000000L just takes off enough digits from the system time to make it an int. Subtracting (42L*365L*24L*60L*60L*1000L) [to get time since Jan 1st 2012] does not make it small enough for int or float values.
I've searched through a ton of sound documentation here but can't find anything about creating and playing a sound from a function, like a sine wave, or an array that could be derived from a function. Is that possible in processing?
Hello, I'm trying to write a template program for buttons and menus, but I run into a NullPointerException when I try and construct the button class, in line 17.
I am new to Processing, and I have never used Classes before.
Here is my code:
int menu = 1;
Button[] mainmenu;
//Button[] optionsmenu;
//Button[] levels;
//Button[] game;
void drawMenu(Button[] m){
for (int i = 0; i < m.length; i++){
m[i].draw();
}
}
void setup(){
size(800, 640);
//pos x, pos y, size x, size y, to menu id, from menu id, image name
mainmenu[0] = new Button(width/2, height/3, 160, 40, 3, 1, "PlayButton.jpg");
mainmenu[1] = new Button(width/2, height/2, 160, 40, 2, 1, "OptionsButton.jpg");
mainmenu[2] = new Button(width/2, 2*height/3, 160, 40, 999, 1, "ExitButton.jpg");
}
void draw(){
background(0);
if (menu == 1){
drawMenu(mainmenu);
}
}
class Button {
int px;
int py;
int sx;
int sy;
int ToMenu;
int InMenu;
String sprite;
PImage img;
//Constructor!
Button(int tpx, int tpy, int tsx, int tsy, int tToMenu, int tInMenu, String sprite){
img = loadImage(sprite);
px = tpx;
py = tpy;
sx = tsx;
sy = tsy;
ToMenu = tToMenu;
InMenu = tInMenu;
}
void draw(){
image(img, px-(sx/2), py-(sy/2));
}
void mouseover(){
if (mouseX > px-(sx/2) && mouseX < px+(sx/2)){
if (mouseY > py-(sy/2) && mouseY < py+(sy/2)){
menu = ToMenu;
}
}
}
//End Class
}
void mousePressed(){
if (menu==1){
for (int i = 0; i < 3; i++){
mainmenu[i].mouseover();
}
}
}
Here is the error stack:
Exception in thread "Animation Thread" java.lang.NullPointerException
at Buttons.setup(Buttons.java:35)
at processing.core.PApplet.handleDraw(PApplet.java:2103)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:190)