Mike
Mike

Reputation: 1610

Android SmackInitialization: org.xmlpull.v1.XmlPullParserFactory.newInstance Error

I keep getting the below error message and I can't figure out why. Any help would be appreciated:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
    at org.jivesoftware.smack.ConnectionConfiguration.<clinit>(ConnectionConfiguration.java:38)
    at com.parental.control.XmppClient.connect(XmppClient.java:32)
    at com.parental.control.XmppClient.main(XmppClient.java:23)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.IllegalStateException: java.lang.RuntimeException: Stub!
    at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:119)
    ... 9 more
Caused by: java.lang.RuntimeException: Stub!
    at org.xmlpull.v1.XmlPullParserFactory.newInstance(XmlPullParserFactory.java:16)
    at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:153)
    at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:148)
    at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:116)
    ... 9 more

Just running the below code:

private void connect() throws InterruptedException, IOException, XMPPException, SmackException {
    XMPPTCPConnectionConfiguration conf = XMPPTCPConnectionConfiguration.builder().setServiceName(hostName).setHost(<openFireServerHost).setPort(5222).setUsernameAndPassword(userName, password).setCompressionEnabled(false).build();
    XMPPTCPConnection connection = new XMPPTCPConnection(conf);
}

Upvotes: 0

Views: 544

Answers (2)

vitalyster
vitalyster

Reputation: 5266

You have compiled your application with android library stub, read the docs:

By default, the Android Plug-in for Gradle executes your local unit tests against a modified version of the android.jar library, which does not contain any actual code. Instead, method calls to Android classes from your unit test throw an exception. This is to make sure you test only your code and do not depend on any particular behavior of the Android platform (that you have not explicitly mocked).

So, your build environment isn't configured properly to build a real android application for the device/emulator

Upvotes: 1

Mike
Mike

Reputation: 1610

So . . . this was actually an XMLPullParser error which has nothing to do with the Smack libraries. It took me all weekend to trace through the code and figure this out but the issue was that I was trying to connect to my Open Fire server without using the my Android emulator.

The below Stack Overflow post helped me figure it out: how to instantiate an XmlPullParser in android-8?

Just figured that I would post this for the next slob that runs into this problem.

Upvotes: 0

Related Questions