Search code examples
javaandroid-studioarcgisfilenotfoundexceptionesri

Android Studios not recognizing the asset file that I added


Android Studios 1.0

I have added a file int the app/src/main/assets folder in Android Studios but it still keeps throwing a

unreported exception FileNotFoundException; must be caught or declared to be thrown

So I am trying to create a Geodatabase class using the ERSI ArcGIS API (but the problem I believe has little to do with that). I have tried putting the file (basemap.geodatabase) in various different locations, in the app folder, in the src, main, assets, in a lot of different locations but the IDE won't recognize it. I've even tried just referencing it from the C:/ drive off of my computer but that won't work either. I've read of different people that have had this problem but their solution hasn't worked for me. Here is the code that i'm using when the file is in the src/main/assets folder:

Geodatabase geodatabase = new Geodatabase("/basemap.geodatabase");

i've also tried,

Geodatabase geodatabase = new Geodatabase("{/basemap.geodatabase}");

and

Geodatabase geodatabase = new Geodatabase("/src/main/assets/basemap.geodatabase");

and many different variations of all.

according to the app.iml file, the first line should be right because:

<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />

But it keeps throwing the FileNotFound error. How can I make the IDE recognize this file so that I can use it?


Solution

  • Alright, no worries i'm going to answer my own question, i've found the solution.

    I'm still not quite sure as to why Gradle wasn't packaging the .geodatabase file in the package, but the solution was putting the file on the PHYSICAL device and then in the code referencing it from there, where I knew that it was, as so:

        try {
            geodatabase = new Geodatabase("/sdcard/Geodatabase/basemap.geodatabase");
        } catch (FileNotFoundException e) {
            Log.e("ERROR", "File Not found");
            e.printStackTrace();
        }
    

    So I put the file on my tablet in that place in the file hierarchy(/sdcard/Geodatabase/basemap.geodatabase") and the program found it there.