0

I'm using Android Studio 2.0 and I've created an Android library to keep some classes and a XML data file. The file is placed in the /res directory but I cannot find any way to access it. I always get a FileNotFoundException.

The code I use to open and serialize the file is:

try {
        SomeClass someClass = new SomeClass();
        someClass.entries = new ArrayList<SomeEntry>();
        Serializer serializer = new Persister();

        InputStream file=assetManager.open("simple.xml");
        someClass= serializer.read(SomeClass.class, file);
    }
    catch (Exception ex)
    {
        ex.getMessage();
    }
ForLowerz
  • 13
  • 5
yian.athanasiadis
  • 527
  • 1
  • 5
  • 6

1 Answers1

0

simple.xml should be inside assets folder.

And make sure that assetManager object is equal to getApplicationContext().getAssets().open("simple.xml");

jayeshsolanki93
  • 2,096
  • 1
  • 20
  • 37