getAssets(); from another class

后端 未结 1 633
予麋鹿
予麋鹿 2020-12-08 01:02

I have a simple read a txt-file function.

AssetManager mngr = getAssets();
InputStream is = mngr.open(\"textdb.txt\");

It works from my mai

相关标签:
1条回答
  • 2020-12-08 01:07

    Is your other class also an Activity? getAssets() is a method of Context. If your class is not an activity, you'll need to pass a context into it and then call getAssets on that.

    Like so:

    public myClass(Context myContext) {
        AssetManager mngr = myContext.getAssets();
        InputStream is = mngr.open("textdb.txt");
    }
    
    0 讨论(0)
提交回复
热议问题