I’m working from Killer Game Programming and trying to modify the code so that i can use it in my project, which is still in early development. i’m using Netbeans.
I’ve got this bunch of errors:
run:
Reading file: images\BoganImagesLoader.txt
Exception in thread “main” java.lang.NullPointerException
at java.io.Reader.(Reader.java:78)
at java.io.InputStreamReader.(InputStreamReader.java:72)
at barbarplatform.ImagesLoader.loadImagesFile(ImagesLoader.java:55)
at barbarplatform.ImagesLoader.(ImagesLoader.java:35)
at barbarplatform.GamePanel.(GamePanel.java:90)
at barbarplatform.BarbarPlatform.main(BarbarPlatform.java:29)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)
Which i think are related to the location of my images folder.
Code snippet where the first two errors are coming from:
public class ImagesLoader {
private final static String IMAGE_DIR = "images/";
private HashMap imagesMap;
/* The key is the filename prefix, the object (value)
is an ArrayList of BufferedImages */
private HashMap gNamesMap;
/* The key is the 'g' <name> string, the object is an
ArrayList of filename prefixes for the group. This is used to
access a group image by its 'g' name and filename. */
private GraphicsConfiguration gc;
public ImagesLoader(String fnm){
//begin by loading images specified in fnm
initLoader();
loadImagesFile(fnm); //line 35 here
} //end of ImagesLoader()
public ImagesLoader(){
initLoader();
}
private void initLoader(){
imagesMap = new HashMap();
gNamesMap = new HashMap();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
} //end of initLoader()
private void loadImagesFile(String fnm){
String imsFNm = IMAGE_DIR + fnm;
System.out.println("Reading file: " + imsFNm);
try{
InputStream in = this.getClass().getResourceAsStream(imsFNm);
BufferedReader br = new BufferedReader(new InputStreamReader(in)); //line 55 here
String line;
char ch;
while ((line = br.readLine()) != null){
if(line.length() == 0) //blank line
continue;
else if(line.startsWith("//")) //comment
continue;
ch = Character.toLowerCase(line.charAt(0));
if(ch == 'o') //a single image
getFileNameImage(line);
// else if(ch == 'n') //a numbered sequence of images
// getNumberedImages(line);
else if(ch == 's') //an images strip
getStripImages(line);
// else if (ch == 'g') //a group of images
// getGroupImages(line);
else
System.out.println("Do not recognize line " + line);
}
br.close();
}catch (IOException ioe){
System.out.println("Error reading file: " + imsFNm + ioe);
System.exit(1);
}
} //end of loadImagesFile
Any ideas from this? I can post more stuff and try a few things if there are any suggestions.
Thanks.