2017-10-22 106 views
0

我不斷收到下面的錯誤信息,我找不出原因。任何幫助,將不勝感激:Android SmackInitialization:org.xmlpull.v1.XmlPullParserFactory.newInstance錯誤

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 

只需運行下面的代碼:

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); 
} 

回答

0

左右。 。 。這實際上是一個XMLPullParser錯誤,與Smack庫無關。我花了整個週末的時間來跟蹤代碼並找出這個問題,但問題是我試圖連接到我的Open Fire服務器而不使用我的Android模擬器。

下面的堆棧溢出後幫我弄明白:how to instantiate an XmlPullParser in android-8?

只是想通,我會發布此爲運行到這個問題下一個邋遢。

1

您已經編譯了Android庫存根你的應用程序,閱讀docs

默認情況下,Android的插件的搖籃反對執行當地的單元測試的android.jar庫的修改版本,其中不包含任何實際的代碼。相反,從你的單元測試中調用Android類的方法會引發異常。這是爲了確保您只測試您的代碼,並且不依賴於Android平臺的任何特定行爲(您尚未明確地嘲笑)。

所以,你的編譯環境未正確配置,以建立該設備/模擬器真正的Android應用程序