Author Topic: NullPointerException loading .zip File need Help  (Read 2718 times)

Offline dubbox

  • byte
  • *
  • Posts: 24
    • View Profile
NullPointerException loading .zip File need Help
« on: September 18, 2014, 09:13:20 pm »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: NullPointerException loading .zip File need Help
« Reply #1 on: September 18, 2014, 10:35:04 pm »
Most likely because you got this wrong:

Code: [Select]
  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.


Offline dubbox

  • byte
  • *
  • Posts: 24
    • View Profile
Re: NullPointerException loading .zip File need Help
« Reply #2 on: September 19, 2014, 11:10:33 am »
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

Offline dubbox

  • byte
  • *
  • Posts: 24
    • View Profile
Re: NullPointerException loading .zip File need Help
« Reply #3 on: September 19, 2014, 11:15:20 am »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: NullPointerException loading .zip File need Help
« Reply #4 on: September 19, 2014, 12:37:00 pm »
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.

Offline dubbox

  • byte
  • *
  • Posts: 24
    • View Profile
Re: NullPointerException loading .zip File need Help
« Reply #5 on: September 19, 2014, 02:12:07 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: NullPointerException loading .zip File need Help
« Reply #6 on: September 19, 2014, 02:41:37 pm »
Yes, as said: Name the file .mp3 instead of .zip.

Offline dubbox

  • byte
  • *
  • Posts: 24
    • View Profile
Re: NullPointerException loading .zip File need Help
« Reply #7 on: September 19, 2014, 02:45:29 pm »
that is what i did still no change :(

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: NullPointerException loading .zip File need Help
« Reply #8 on: September 19, 2014, 03:01:02 pm »
That's strange. This hack always worked for me. Then try to move it into the assets folder instead of res/raw.