Android Question Problem with third party lib

Marcio Almeida

Member
Licensed User
Longtime User
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:

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:

Brandsum

Well-Known Member
Licensed User
Please use code tag while posting codes.

Are you trying to wrap the lib? or use it via javaobject ?
 
Upvote 0

Marcio Almeida

Member
Licensed User
Longtime User
Sorry, my english is not good. Maybe I got it wrong, wrote in b4a and used javaobject, according to the code below:

B4X:
Dim class As JavaObject
class.InitializeNewInstance("br.com.bematech.android.usb.mp4200th.Printer", Null)

The error happens when instantiating the Printer class.

Thanks!
 
Upvote 0

Brandsum

Well-Known Member
Licensed User
I don't think it's a working library as the error is coming from the library when you are following the documentation. Or maybe the documentation is incorrect.
 
Upvote 0
Top