Hi,
When registering ZipLocator using zip that might not exist. like in zip are build and use only when running in deploy mode
while in debug mode via JMP or Eclipse, asset will be found in classpath…
so When this happen, in setRootPath we can see a catch that trap the fact that zip is not here. This is good
[java]public void setRootPath(String rootPath) {
try{
zipfile = new ZipFile(new File(rootPath), ZipFile.OPEN_READ);
}catch (IOException ex){
logger.log(Level.WARNING, "Failed to open zip file: "+rootPath, ex);
}
}[/java]
But when the locator is used, it assume it was successfully open as no check is done when
calling the zipfile.getEntry
[java] public AssetInfo locate(AssetManager manager, AssetKey key) {
String name = key.getName();
ZipEntry entry = zipfile.getEntry(name);
if (entry == null)
return null;[/java]
so Boom a nice NullPointerException
Here is a simple fix I propose that will solve that
[java] public AssetInfo locate(AssetManager manager, AssetKey key) {
//check if Zip was not here and so failed when setRootPath was called
if(zipfile == null) return null;
String name = key.getName();
ZipEntry entry = zipfile.getEntry(name);
if (entry == null)
return null;[/java]