嗨我正在使用推送器进行通知,经过一些测试我一直遇到麻烦,现在当我打算加载任务时,我有了这条消息。
02-08 13:43:56.751 20712-21208/package E/AndroidRuntime: FATAL EXCEPTION: pusher-java-client eventQueue
java.lang.NoClassDefFoundError: com.pusher.client.connection.websocket.WebSocketClientWrapper
at com.pusher.client.util.Factory.newWebSocketClientWrapper(Factory.java:67)
at com.pusher.client.connection.websocket.WebSocketConnection$1.run(WebSocketConnection.java:63)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:841)
这就是我在onCreate中调用pusher连接的方式
runOnUiThread(new Runnable() {
@Override
public void run() {
// Create a new Pusher instance
Pusher pusher = new Pusher("KEY");
pusher.connect(new ConnectionEventListener() {
@Override
public void onConnectionStateChange(ConnectionStateChange change) {
System.out.println("State changed to " + change.getCurrentState() +
" from " + change.getPreviousState());
}
@Override
public void onError(String message, String code, Exception e) {
System.out.println("There was a problem connecting!");
}
}, ConnectionState.ALL);
Channel channel = pusher.subscribe("my-channel");
channel.bind("my-event", new SubscriptionEventListener() {
@Override
public void onEvent(String channel, String event, String data) {
System.out.println("Received event with data: " + data);
}
});
pusher.disconnect();
pusher.connect();
logger.info("Hubo un problema al conectarse");
}
});
我被困在这里,我不知道如果我以一种糟糕的方式执行线程,一些提示会有所帮助,谢谢!
答案 0 :(得分:0)
此错误背后的原因是android VM中的64K限制
要解决它,你应该下载这个jar:
http://central.maven.org/maven2/com/pusher/pusher-java-client/1.2.1/pusher-java-client-1.2.1-jar-with-dependencies.jar
添加它并从项目依赖项中删除任何现有的java-client- *
同时从gradle.build文件中删除任何com.google.gson
最后,在项目中启用multidex:
https://developer.android.com/studio/build/multidex.html
这对我有用。