FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   null pointer exception
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: null pointer exception  (Read 351 times)
jamest


null pointer exception
« on: Jan 25th, 2005, 4:27am »

Below is my sketch. The complier complains with "java.lang.NullPointerException" at several points such as at PdeRuntime.start(PdeRuntime.java:346) OR at PdeEditor.doRun(PdeEditor.java:807). Can anyone help me out finding out what's wrong with the code? It seems to me that there's something wrong with my code in the setup() section?
 
-----
 
String lines[] = loadStrings("list.txt");  
keyword[] keywords = new keyword[lines.length];
 
 
void setup() {
 size(300,600);
 background(255,255,102);
 //set font
 BFont keywordFont;  
 keywordFont = loadFont("Univers55.vlw.gz");  
 textFont(keywordFont, 22);  
 
 // setup the keyword array
 for(int i=0; i<lines.length; i++) {
   keywords[i] = new keyword(lines[i], (int)random(30,300), 15);
 }
 framerate(1);
}
 
void loop(){
  rect(0,0,width,height);
  background(255,255,102);
  // draws each keyword
  for(int i=0; i< lines.length; i++){
    keywords[i].draw();
    keywords[i].moveY(20);
  }
}
 
class keyword{
   String keywordString;
   int posX, posY;
   //constructor
   keyword(String str, int posX, int posY){
 keywordString = str;
 this.posX = posX;
 this.posY = posY;      
   }
   
   void draw(){
 text(keywordString, posX, posY);
   }
   
   void moveY(int mY) {
     posY+=mY;
     if (posY > height) {
 posY = 0;
     }
   }
}
------
 
thank you!
 
 
eskimoblood

222550793222550793 WWW
Re: null pointer exception
« Reply #1 on: Jan 25th, 2005, 10:05am »

I believe you cannot load the String befor the setup methode
 
Code:

String [] lines;
keyword [] keywords;
 
void setup(){
  size(200,400);
  lines = loadStrings("list.txt");
  keywords = new keyword[lines.length];
 
  BFont keywordFont;  
  keywordFont = loadFont("Tahoma.vlw");  
  textFont(keywordFont, 22);  
 
  // setup the keyword array
  for(int i=0; i<lines.length; i++) {
    keywords[i] = new keyword(lines[i],    (int)random(30,300), 15);
  }
  framerate(1);
}
 
jamest


Re: null pointer exception
« Reply #2 on: Jan 26th, 2005, 6:19am »

yeah, this works. many thanks!
 
Pages: 1 

« Previous topic | Next topic »