I am trying to get AssetManager
form a class in an Android library project, but I am getting the error:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
This is how I call it:
public class RevPluginLoader extends AppCompatActivity {
private List<String> copyPlugins() {
AssetManager assetManager = getAssets(); // This is where it all fails
}
}
How can I get the AssetManager
?
We can't add assets folder in lib module
Library modules cannot include raw assets The tools do not support the use of raw asset files (saved in the assets/ directory) in a library module. Any asset resources used by an app must be stored in the assets/ directory of the app module itself.
For More details, you can refer here
I think you have a onCreateView
public class RevPluginLoader extends AppCompatActivity {
private Context mContext = null; //declare a context here
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this; //assign class object to context
}
private List<String> copyPlugins() {
AssetManager assetManager = mContext.getAssets(); //use context here
}
}
Check commented lines
This may solve your problem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With