Hello guys! I'm trying to use the lib below, but I can't. This is the first time having a third-party lib using b4a. I am getting the message the following error:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Looper android.content.Context.getMainLooper()' on a null object reference
at br.com.bematech.android.usb.mp4200th.Printer.<init>(Printer.java:77)
at java.lang.Class.newInstance(Native Method)
When I run the code:
Below the code of the class where I believe the error is occurring:
public Printer() {
this.context = ApplicationContextProvider.getContext();
this.mainHandler = new Handler(this.context.getMainLooper());
}
As I understand it, the error is occurring because this.context is null. But I can't understand why it is null, below the code of the ApplicationContextProvider class:
public class ApplicationContextProvider extends Application {
private static Context sContext;
public ApplicationContextProvider() {
}
public void onCreate() {
super.onCreate();
sContext = this.getApplicationContext();
}
public static Context getContext() {
return sContext;
}
}
Thanks for any help.
java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Looper android.content.Context.getMainLooper()' on a null object reference
at br.com.bematech.android.usb.mp4200th.Printer.<init>(Printer.java:77)
at java.lang.Class.newInstance(Native Method)
When I run the code:
B4X:
Dim class As JavaObject
class.InitializeNewInstance("br.com.bematech.android.usb.mp4200th.Printer", Null)
Below the code of the class where I believe the error is occurring:
public Printer() {
this.context = ApplicationContextProvider.getContext();
this.mainHandler = new Handler(this.context.getMainLooper());
}
As I understand it, the error is occurring because this.context is null. But I can't understand why it is null, below the code of the ApplicationContextProvider class:
public class ApplicationContextProvider extends Application {
private static Context sContext;
public ApplicationContextProvider() {
}
public void onCreate() {
super.onCreate();
sContext = this.getApplicationContext();
}
public static Context getContext() {
return sContext;
}
}
Thanks for any help.
Last edited: