NullPointerException loading .zip File need Help

Started by dubbox, September 18, 2014, 09:13:20 PM

Previous topic - Next topic

dubbox

Hi Guys,
I am currently working on a Project but my problem is i got a big file cause it is a building for a game to move in. I serialized it and now zipped it also cause i had a outofmemory exception but the loading from the zip file doesnt work here is the code

ZipInputStream zis = new ZipInputStream(mContext.getResources().openRawResource(R.raw.ab));
//            try {
//            if(zis.getNextEntry() != null)
//               zis.getNextEntry();                                                               tried this already
//            } catch (IOException e) {e.printStackTrace();}
            model = Loader.loadSerializedObject(zis);
            
//         model.calcTextureWrapSpherical();
//            model.setTexture("texture");
            model.strip();

            model.scale(10);
            model.build();
            
            world.addObject(model);


the exception i get is: (im not getting whats actually wrong here so i ask you guys)

Systemerr:
java.lang.NullPointerException at com.threed.jpct.DeSerializer.deserialize(DeSerializer.java:61)
                                       at com.threed.jpct.Loader.loadSerializedObject(Loader.java:104)
                         at and.testandroid.JPCTAESkeletonActivity$MyRenderer.onSurfaceChanged(JPCTAESkeletonActivity.java:197)
                                           at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1325)
                                      at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)

so i get this fatal error
java.lang.RuntimeException: [ 1411066378308 ] - ERROR: Can't deserialize object: null

i know that the loader seems not to load the file correctly but why?
file is located in res/raw/ab.zip/ab.ser
so what am i missing here that it cannot be loaded?

i serlialized the object with that code
Object3D model = null;
        String modelName = "ab";
     //   TextureManager.getInstance().flush();


       //TextureManager tm = TextureManager.getInstance();
       //Texture grass2 = new Texture("C:/Worksapce/SaveMe/res/raw/f15e.jpg");
        DeSerializer de = new DeSerializer();
        model = model.mergeAll(Loader.load3DS(new FileInputStream("C:/Users/Jascha/documents/3DObjects/"+modelName+".3ds"), 1));
        model.build();
        de.serialize(model, new FileOutputStream("C:/users/Jascha/documents/3DObjects/serialized/"+modelName+".ser"), true);

code worked fine with small models and without zip

Thank you for your help

EgonOlsen

Most likely because you got this wrong:


  try {
      if(zis.getNextEntry() != null) {
         zis.getNextEntry();
      }                                                           
  } catch (IOException e) {e.printStackTrace();}


That's not correct, because you are actually calling getNextEntry() twice. The first call will read the actual entry that you want to load but you are ignoring it and move it to the next one instead, which is null.

Don't do this null checking...just call getNextEntry() once.


dubbox

I get excactly the same error Egon ;(
I dont know its the same error in the line where the loader loads the obj out of the zipinputstream

i changed the code like this

ZipInputStream zis = new ZipInputStream(mContext.getResources().openRawResource(R.raw.ab));
            try {
               zis.getNextEntry();                                                               
            } catch (IOException e) {e.printStackTrace();}
            model = Loader.loadSerializedObject(zis);

what am i missing here it still says null pointer exception and after that that you cant deserialize object null

dubbox

C:\Users\Jascha\workspace\TestAndroid\res\raw\ab.zip thats the correct file path testandroid is my project and in ab.zip is ab.ser

EgonOlsen

Look for some log output... Depending in the Android version, there are restrictions to the maximum size of a file depending in the type. Try to name the file .mp3 instead, because extension has no restrictions.

dubbox

Data exceeds UNCOMPRESS_DATA_MAX (3584357 vs 1048576)
seems like that is the problem rigth here? can i do sth about that or do i have to reduce the memoryspace my model needs?

EgonOlsen

Yes, as said: Name the file .mp3 instead of .zip.

dubbox


EgonOlsen

That's strange. This hack always worked for me. Then try to move it into the assets folder instead of res/raw.