Using getAssets() gives the error "The method getAssets() is undefined for the type ClassName"?
android, java
Solution
I am trying to open a file which is in the assets folder. But using getAssets() gives the error given above.
`getAssets()` is a method on `Context`.
I know I have to pass the context from another activity, but I can't do that either as then another error comes-"The method onCreate(SQLiteDatabase, Context) of type ClassName must override or implement a supertype method".
Since you declined to paste the source code where this is occurring, it is difficult to help you.
ClassName is not an activity, it's just a class
More specifically, it is a subclass of `SQLiteOpenHelper`.
so getAssets() cannot work without passing context from another activity.
A `SQLiteOpenHelper` gets passed a `Context` to its constructor, which you need to override.
Beyond all of this, if your objective is to package a database with your app, please use `SQLiteAssetHelper`, as it has solved this problem.
Problem
I am trying to open a file which is in the assets folder. But using getAssets() gives the error given above. I know I have to pass the context from another activity, but I can't do that either as then another error comes-"The method onCreate(SQLiteDatabase, Context) of type ClassName must override or implement a supertype method". So I am stuck. Is there a better way of opening that file? Here is the line: ``` InputStream is = getAssets().open("file1.txt"); ``` *Note: ClassName is not an activity, it's just a class, so getAssets() cannot work without passing context from another activity. Edit: Here is the class and onCreate declaration: ``` public class DatabaseHandler extends SQLiteOpenHelper { @Override public void onCreate(SQLiteDatabase db) {//some stuff InputStream is = getAssets().open("file1.txt"); //more stuff } } ```