Skip to content Skip to sidebar Skip to footer

Android Getassets() Method Throws Nullpointerexception

I'm trying to get assets of my app from Service and i get nullpointexception. I found few articles about it.but i don't get where my mistake. Where is the code: public class OCRSer

Solution 1:

The next time, please indicate which is line number 41 here. IMHO this was only partial code making the stack trace unusable

The problem i think is here:

AssetManagerassetManager= getAssets();
            for (String file : assetManager.list("tessdata")) {
                InputStreamin= assetManager.open("tessdata/" + file);

if assetManager.list("tessdata") returns a null (that there is no tessdata), that null goes into String file as one entry, then you're calling

InputStreamin= assetManager.open("tessdata/" + file);

"tessdata/" + file will not exist if "tessdata" didn't exist

So, the solution might be:

Solution

for (String file : assetManager.list("tessdata")) {
if(file!=null){
                InputStreamin= assetManager.open("tessdata/" + file);
...
    }
}

Post a Comment for "Android Getassets() Method Throws Nullpointerexception"