0

My Package is: com.abdulwasaetariq.odnvt. I have a folder named tessdata in res/raw/

In the Tesseract API, there is this init function whose documentation and prototype is:

/* @param datapath the parent directory of tessdata ending in a forward
 *            slash
 * @param language an ISO 639-3 string representing the language(s)
 * @return <code>true</code> on success
 */
public boolean init(String datapath, String language) {
    return init(datapath, language, OEM_DEFAULT);
}

Looking on the internet told me that the way to give path to a resource file is like: android.resource://com.packageName

But i am getting the error java.lang.IllegalArgumentException: Data path does not exist!

Here is my relevant code:

    private static void initTess() {
    String dataPath = "android.resource://"+ context.getPackageName() + "/raw/";
    Log.d(TAG, "initTess: dataPath: " + dataPath);
    tessBaseAPI.init(dataPath,"eng");
}

The context.getPackageName() does in fact get me the correct package name com.abdulwasaetariq.odnvt

I wonder where the fault is.

Abdul Wasae
  • 3,614
  • 4
  • 34
  • 56

1 Answers1

3

The problem is that android.resource:// is not a valid way to access resources in your app's res/raw/ folder, so the error message you see is being caused by the invalid path.

Try moving your files to assets/ and using AssetManager to copy the files to your device instead.

rmtheis
  • 5,992
  • 12
  • 61
  • 78
  • Ahan. I know about the AssetManager approach. But though what if i specifically wanted to refer to a raw file in res/raw folder? There must be a way to surely, right? – Abdul Wasae Jul 05 '16 at 13:59
  • Yes--click the first link in my answer and look at Table 1. – rmtheis Jul 05 '16 at 14:02