Johanovski
Johanovski

Reputation: 31

Unable to access Android assets (and no post or tutorial works for me), please help!

I'm facing a kind of curse about asset accessing with Android. I'm using NetBeans 6.9.1 and testing on a 2.3 Android Virtual Device. I'm trying to access a database file ("database.db") stored in the assets folder (though I've had to make the directory by myself because it didn't even existed in my project folder) and I'm simply unable to do it after more than 3 days lost looking for a solution. Here a summary of my tragic process:

I've also tried to access it from the MainActivity itself:

try{
        AssetManager mng = this.getAssets();
        String[] str = mng.list("");
        // The same three elements...

        // And this explodes in a nuclear toxic cloud that kills a thousand birds
        InputStream is = this.getAssets().open("sub/sample.txt");
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = null;
        int number = 0;
        while ((line = br.readLine()) != null) {
            number++;
        }
        br.close();
    }catch(Exception e){
        // Life is sad...
    }

And now, some questions: What I'm doing wrong? Is my assets folder correctly placed? Are my files correclty copied? Is my code correctly placed?

Upvotes: 3

Views: 7188

Answers (2)

david
david

Reputation: 1

i had this problem and i suggest you check couple of things:

  1. If the directory name is written in english.
  2. you have just one directory in your assets root (in this one directory you can insert couple of drectories).

For example: assets -> app -> image, assets -> app -> another dir. In this example the app dir is the only dir in the asssete root.

Upvotes: 0

Balaji
Balaji

Reputation: 285

To fix:

Create a directory called ‘assets’ at your project root (same dir that AndroidManifest.xml lives)

In /nbproject/project.properties, change

*add these two lines (it wont exist)*

assets.dir=assets assets.available=true

In /nbproject/build-impl.xml,

there is line in the “if=assets.available” target that reads

that needs to be changed to

That’s it – you should be all set and “file:///android_asset/” should be accessible to your application and contain the contents of your project’s assets directory.

Got this link and it worked for me!!...

http://blog.yetisoftware.com/2009/04/02/android-netbeans-and-the-assets-directory/

Upvotes: 2

Related Questions