You need to create an empty contructor in your Java class:
public class main {
// Initalize context
Context mContext;
public main(){
}
public main(Context mContext){
this.mContext = mContext;
}
public boolean main() {
Log.d("MYLOG", "main() called successfully when there context is not initialized like above");
// some code here
}
}
This will only call the empty constructor, which may not be what you want.
Alternatively, you need to choose the constructor you want and add a parameter to your newInstance call (see related SO question here) like so:
Class[] cArg = new Class[1];
cArg[0] = Context.class;
classToLoad.getDeclaredConstructor(cArg).newInstance(context);
so your non-empty constructor
public main(Context mContext)
is called.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…