Android jawampa - ApplicationError(wamp.error.invalid_uri,[],{})。使用正确的URI格式,但仍然崩溃

时间:2017-02-10 21:38:19

标签: android wamp autobahn

我已经测试了我在多个设备上执行的过程,但是,当我开始在Android上使用它时,它始终会失败。

我一直在使用WAMP在多个设备之间进行通信。似乎没有官方支持Android上的Autobahn支持WAMP jawampa应该这样做。

我使用Android Studios将此模块包含在Android项目中。 我对Android开发很陌生,所以我尝试从我有更多经验的地方解决问题。我认为在Android上使用它时可能会出现问题。

以下是我对该项目的设置。

app gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.1"
    defaultConfig {
        applicationId "com.example.user.androidapp"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        jackOptions {
            enabled true
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/io.netty.versions.properties'
        exclude 'META-INF/INDEX.LIST'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.1'
    compile 'com.android.support:design:25.1.1'
    testCompile 'junit:junit:4.12'
    compile 'ws.wamp.jawampa:jawampa-core:0.4.2'
    compile 'ws.wamp.jawampa:jawampa-netty:0.4.2'
}

我设置了权限<uses-permission android:name="android.permission.INTERNET" />

WAMP代码:

package com.example.cdrandin.androidapp;

import android.util.Log;

import java.util.concurrent.TimeUnit;

import rx.functions.Action1;
import ws.wamp.jawampa.WampClient;
import ws.wamp.jawampa.WampClientBuilder;
import ws.wamp.jawampa.WampError;
import ws.wamp.jawampa.transport.netty.NettyWampClientConnectorProvider;

public class WampTasks {
    private static WampTasks _ourInstance = new WampTasks();
    private static String _host = "192.168.2.201";
    private static String _port = "8080";

    public static WampTasks getInstance() {
        return _ourInstance;
    }

    public WampClient client = null;

    private WampTasks() {
        try {
            // Create a builder and configure the client
            WampClientBuilder builder = new WampClientBuilder();
            NettyWampClientConnectorProvider connectorProvider = new NettyWampClientConnectorProvider();
            builder.withConnectorProvider(connectorProvider)
                    .withUri(String.format("ws://%s:%s/ws", _host, _port))
                    .withRealm("realm1")
                    .withInfiniteReconnects()
                    .withReconnectInterval(5, TimeUnit.SECONDS);

            // Create a client through the builder. This will not immediately start
            // a connection attempt
            client = builder.build();
        } catch (WampError e) {
            // Catch exceptions that will be thrown in case of invalid configuration
            e.printStackTrace();
            return;
        } catch(Exception e) {
            e.printStackTrace();
            return;
        }
    }

    public void Alert(String ip){
        client.publish("com.app.test", "hello world");
    }
}

崩溃报告:

02-10 13:46:16.824 2872-2878/com.example.user.androidapp W/art: Suspending all threads took: 45.899ms
02-10 13:46:16.830 2872-2872/com.example.user.androidapp W/System.err: ApplicationError(wamp.error.invalid_uri, [], {})
02-10 13:46:16.833 2872-2872/com.example.user.androidapp W/System.err:     at ws.wamp.jawampa.transport.netty.NettyWampClientConnectorProvider.createConnector(NettyWampClientConnectorProvider.java:102)
02-10 13:46:16.833 2872-2872/com.example.user.androidapp W/System.err:     at ws.wamp.jawampa.WampClientBuilder.build(WampClientBuilder.java:127)
02-10 13:46:16.833 2872-2872/com.example.user.androidapp W/System.err:     at com.example.user.androidapp.WampTasks.<init>(WampTasks.java:40)
02-10 13:46:16.833 2872-2872/com.example.user.androidapp W/System.err:     at com.example.user.androidapp.WampTasks.<clinit>(WampTasks.java:17)
02-10 13:46:16.833 2872-2872/com.example.user.androidapp W/System.err:     at com.example.user.androidapp.SelectedDevice.onCreate(SelectedDevice.java:13)
02-10 13:46:16.834 2872-2872/com.example.user.androidapp W/System.err:     at android.app.Activity.performCreate(Activity.java:5990)
02-10 13:46:16.834 2872-2872/com.example.user.androidapp W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
02-10 13:46:16.834 2872-2872/com.example.user.androidapp W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
02-10 13:46:16.834 2872-2872/com.example.user.androidapp W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
02-10 13:46:16.845 2872-2872/com.example.user.androidapp W/System.err:     at android.app.ActivityThread.access$800(ActivityThread.java:151)
02-10 13:46:16.845 2872-2872/com.example.user.androidapp W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
02-10 13:46:16.845 2872-2872/com.example.user.androidapp W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
02-10 13:46:16.845 2872-2872/com.example.user.androidapp W/System.err:     at android.os.Looper.loop(Looper.java:135)
02-10 13:46:16.846 2872-2872/com.example.user.androidapp W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5254)
02-10 13:46:16.846 2872-2872/com.example.user.androidapp W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
02-10 13:46:16.847 2872-2872/com.example.user.androidapp W/System.err:     at java.lang.reflect.Method.invoke(Method.java:372)
02-10 13:46:16.847 2872-2872/com.example.user.androidapp W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
02-10 13:46:16.847 2872-2872/com.example.user.androidapp W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
02-10 13:46:16.848 2872-2872/com.example.user.androidapp D/AndroidRuntime: Shutting down VM
02-10 13:46:16.849 2872-2872/com.example.user.androidapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                               Process: com.example.user.androidapp, PID: 2872
                                                                               java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.user.androidapp/com.example.user.androidapp.SelectedDevice}: java.lang.NullPointerException: Attempt to invoke virtual method 'rx.Observable ws.wamp.jawampa.WampClient.publish(java.lang.String, java.lang.Object[])' on a null object reference
                                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
                                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
                                                                                   at android.app.ActivityThread.access$800(ActivityThread.java:151)
                                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                   at android.os.Looper.loop(Looper.java:135)
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:5254)
                                                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                                                   at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
                                                                                Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'rx.Observable ws.wamp.jawampa.WampClient.publish(java.lang.String, java.lang.Object[])' on a null object reference
                                                                                   at com.example.user.androidapp.WampTasks.Alert(WampTasks.java:66)
                                                                                   at com.example.user.androidapp.SelectedDevice.onCreate(SelectedDevice.java:13)
                                                                                   at android.app.Activity.performCreate(Activity.java:5990)
                                                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
                                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
                                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
                                                                                   at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                   at android.os.Looper.loop(Looper.java:135) 
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:5254) 
                                                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                                                   at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
                                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
02-10 13:46:16.873 2872-2883/com.example.user.androidapp I/art: Background partial concurrent mark sweep GC freed 607(56KB) AllocSpace objects, 0(0B) LOS objects, 40% free, 2MB/3MB, paused 10.990ms total 146.347ms
02-10 13:46:19.630 2872-2872/com.example.user.androidapp I/Process: Sending signal. PID: 2872 SIG: 9

1 个答案:

答案 0 :(得分:0)

You Uri是你的WampBuilder withUri(String.format(&#34; ws://%s:%s / ws&#34;,_ host,_port))中的一个问题。检查它是否正常运行。 使用此网址http://192.168.2.201:8080启动浏览器。 Normarly你会看到像#34这样的wamp消息;这个服务器在路径/ ws上提供了一个wamp路由器&#34;