无法在Android中的SmackInitialization中获得smack版本

时间:2015-11-21 19:30:08

标签: android xmpp chat smack

我正在使用Smack进行XMPP聊天应用。我在SmackInitialization类中得到一个奇怪的异常,其中出现错误无法确定Smack版本然后App崩溃。我搜索得足够多,但没有找到我错的地方。请提供相关的可能解决方案。

崩溃日志:

26905-26905/com.myoneapp.chat E/SmackInitialization﹕ Could not determine Smack version
    java.lang.NullPointerException: lock == null
            at java.io.Reader.<init>(Reader.java:64)
            at java.io.InputStreamReader.<init>(InputStreamReader.java:122)
            at java.io.InputStreamReader.<init>(InputStreamReader.java:57)
            at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:61)
            at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
            at org.jivesoftware.smack.ConnectionConfiguration.<clinit>(ConnectionConfiguration.java:38)
            at com.myoneapp.chat.services.MyXMPP.initialiseConnection(MyXMPP.java:111)
            at com.myoneapp.chat.services.MyXMPP.init(MyXMPP.java:105)
            at com.myoneapp.chat.services.MyXMPP.<init>(MyXMPP.java:68)
            at com.myoneapp.chat.services.MyXMPP.getInstance(MyXMPP.java:78)
            at com.myoneapp.chat.services.MyService.onCreate(MyService.java:37)
            at android.app.ActivityThread.handleCreateService(ActivityThread.java:2877)
            at android.app.ActivityThread.-wrap4(ActivityThread.java)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1427)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:148)
            at android.app.ActivityThread.main(ActivityThread.java:5417)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-22 00:49:39.572  26905-26905/com.myoneapp.chat D/AndroidRuntime﹕ Shutting down VM
11-22 00:49:39.573  26905-26905/com.myoneapp.chat E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.myoneapp.chat, PID: 26905
    java.lang.ExceptionInInitializerError
            at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
            at org.jivesoftware.smack.ConnectionConfiguration.<clinit>(ConnectionConfiguration.java:38)
            at com.myoneapp.chat.services.MyXMPP.initialiseConnection(MyXMPP.java:111)
            at com.myoneapp.chat.services.MyXMPP.init(MyXMPP.java:105)
            at com.myoneapp.chat.services.MyXMPP.<init>(MyXMPP.java:68)
            at com.myoneapp.chat.services.MyXMPP.getInstance(MyXMPP.java:78)
            at com.myoneapp.chat.services.MyService.onCreate(MyService.java:37)
            at android.app.ActivityThread.handleCreateService(ActivityThread.java:2877)
            at android.app.ActivityThread.-wrap4(ActivityThread.java)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1427)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:148)
            at android.app.ActivityThread.main(ActivityThread.java:5417)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
     Caused by: java.lang.IllegalStateException: java.lang.IllegalArgumentException: is == null
            at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:119)
            at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
            at org.jivesoftware.smack.ConnectionConfiguration.<clinit>(ConnectionConfiguration.java:38)
            at com.myoneapp.chat.services.MyXMPP.initialiseConnection(MyXMPP.java:111)
            at com.myoneapp.chat.services.MyXMPP.init(MyXMPP.java:105)
            at com.myoneapp.chat.services.MyXMPP.<init>(MyXMPP.java:68)
            at com.myoneapp.chat.services.MyXMPP.getInstance(MyXMPP.java:78)
            at com.myoneapp.chat.services.MyService.onCreate(MyService.java:37)
            at android.app.ActivityThread.handleCreateService(ActivityThread.java:2877)
            at android.app.ActivityThread.-wrap4(ActivityThread.java)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1427)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:148)
            at android.app.ActivityThread.main(ActivityThread.java:5417)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
     Caused by: java.lang.IllegalArgumentException: is == null
            at org.kxml2.io.KXmlParser.setInput(KXmlParser.java:1634)
            at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:155)
            at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:148)
            at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:116)
            at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
            at org.jivesoftware.smack.ConnectionConfiguration.<clinit>(ConnectionConfiguration.java:38)
            at com.myoneapp.chat.services.MyXMPP.initialiseConnection(MyXMPP.java:111)
            at com.myoneapp.chat.services.MyXMPP.init(MyXMPP.java:105)
            at com.myoneapp.chat.services.MyXMPP.<init>(MyXMPP.java:68)
            at com.myoneapp.chat.services.MyXMPP.getInstance(MyXMPP.java:78)
            at com.myoneapp.chat.services.MyService.onCreate(MyService.java:37)
            at android.app.ActivityThread.handleCreateService(ActivityThread.java:2877)
            at android.app.ActivityThread.-wrap4(ActivityThread.java)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1427)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:148)
            at android.app.ActivityThread.main(ActivityThread.java:5417)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

依赖关系:

compile files('libs/smack-android-extensions-4.1.0-rc4.jar')
    compile files('libs/smack-extensions-4.1.0-rc4.jar')
    compile files('libs/smack-java7-4.1.0-rc2.jar')
    compile files('libs/smack-resolver-dnsjava-4.1.0-rc4.jar')
    compile files('libs/smack-sasl-provided-4.1.0-rc2.jar')
    compile files('libs/smack-tcp-4.1.0-rc4.jar')
    compile('org.apache.httpcomponents:httpmime:4.3.6') {
        exclude module: 'httpclient'
    }
    compile 'com.android.support:support-v13:23.0.1'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
    compile 'com.squareup.picasso:picasso:2.4.0'
    compile 'org.apache.httpcomponents:httpclient-android:4.3.5'
    compile 'com.android.support:recyclerview-v7:23.0.1'
    compile 'com.facebook.android:facebook-android-sdk:4.0.0'
    compile 'com.google.android.gms:play-services-identity:8.1.0'
    compile 'com.google.android.gms:play-services-location:8.1.0'
    compile 'xpp3:xpp3:1.1.4c'
    compile 'org.jxmpp:jxmpp-core:0.5.0-alpha6'
    compile 'org.jxmpp:jxmpp-jid:0.5.0-alpha6'
    testCompile 'org.jxmpp:jxmpp-jid:0.5.0-alpha6:tests'
    testCompile 'junit:junit:4.11'
    testCompile 'xmlunit:xmlunit:1.5'
    testCompile 'org.powermock:powermock-module-junit4:1.5.5'
    testCompile 'org.powermock:powermock-api-mockito:1.5.5'
    testCompile 'com.jamesmurty.utils:java-xmlbuilder:0.6'
    testCompile 'net.iharder:base64:2.3.8'

错误码:

static {
        String smackVersion;
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(FileUtils.getStreamForUrl("classpath:org.jivesoftware.smack/version", null)));
            smackVersion = reader.readLine();
            try {
                reader.close();
            } catch (IOException e) {
                LOGGER.log(Level.WARNING, "IOException closing stream", e);
            }
        } catch(Exception e) {
            LOGGER.log(Level.SEVERE, "Could not determine Smack version", e);
            smackVersion = "unkown";
        }
        SMACK_VERSION = smackVersion;

        String disabledClasses = System.getProperty("smack.disabledClasses");
        if (disabledClasses != null) {
            String[] splitDisabledClasses = disabledClasses.split(",");
            for (String s : splitDisabledClasses) SmackConfiguration.disabledSmackClasses.add(s);
        }
        try {
            FileUtils.addLines("classpath:org.jivesoftware.smack/disabledClasses", SmackConfiguration.disabledSmackClasses);
        }
        catch (Exception e) {
            throw new IllegalStateException(e);
        }

        try {
            Class<?> c = Class.forName("org.jivesoftware.smack.CustomSmackConfiguration");
            Field f = c.getField("DISABLED_SMACK_CLASSES");
            String[] sa = (String[]) f.get(null);
            if (sa != null) {
                LOGGER.warning("Using CustomSmackConfig is deprecated and will be removed in a future release");
                for (String s : sa)
                    SmackConfiguration.disabledSmackClasses.add(s);
            }
        }
        catch (ClassNotFoundException e1) {
        }
        catch (NoSuchFieldException e) {
        }
        catch (SecurityException e) {
        }
        catch (IllegalArgumentException e) {
        }
        catch (IllegalAccessException e) {
        }

        InputStream configFileStream;
        try {
            configFileStream = FileUtils.getStreamForUrl(DEFAULT_CONFIG_FILE, null);
        }
        catch (Exception e) {
            throw new IllegalStateException(e);
        }

        try {
            processConfigFile(configFileStream, null);
        }
        catch (Exception e) {
            throw new IllegalStateException(e);
        }

        // Add the Java7 compression handler first, since it's preferred
        SmackConfiguration.compressionHandlers.add(new Java7ZlibInputOutputStream());

2 个答案:

答案 0 :(得分:0)

您遗失了此文件org.jivesoftware.smack/version。通常它位于smack-core.jar内。

答案 1 :(得分:0)

问题出在processConfigFile(...)内部,他们正在使用Android的XmlPullParser,并且它在junit test中不可用:

public static void processConfigFile(InputStream cfgFileStream,
                Collection<Exception> exceptions, ClassLoader classLoader) throws Exception {
    XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
.....