質問

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
}

}

役に立ちましたか?

解決

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

他のヒント

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();
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top