Question

I have a static block in Java .How can i run it's static initialization block.

I see in this solution How to keep a XMPP connection stable on Android with (a)smack?

https://android.googlesource.com/platform/external/smack/+/master/src/org/jivesoftware/smack/ReconnectionManager.java

static {
try {
    Class.forName("org.jivesoftware.smack.ReconnectionManager");
} catch (ClassNotFoundException ex) {
    // problem loading reconnection manager
}

}

Was it helpful?

Solution

when you are calling SmackAndroid.init(Context), it is automatically calling these static classes you can check asmack code for clarification.

if you have any problem related to reconnection then you can check my answer,it is working for me. https://stackoverflow.com/a/23307341/2729665

OTHER TIPS

The static initializer block is run when the class is loaded. If there's nothing else to load the class you can call Class.forName to load it:

try {
    Class.forName("full.name.of.YourClass");
} catch (ClassNotFoundException ex) {
    // installation error? Class not found.
    ex.printStackTrace();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top