Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in Android applications #5

Closed
juanmiguelRuaDev opened this issue Jun 9, 2014 · 19 comments
Closed

Error in Android applications #5

juanmiguelRuaDev opened this issue Jun 9, 2014 · 19 comments

Comments

@juanmiguelRuaDev
Copy link

When I try to open connection to http socket.io server. An exception is thrown by Dalvik :

"Could not find class 'com.gitgub.nkzawa.engineio.client.transports.WebSocket$1" referenced from method com.github.nkzawa.engineio.client.transport.WebSocket.doOpen

From java application run correctly.

@nkzawa
Copy link
Contributor

nkzawa commented Jun 9, 2014

I'm not sure, but it can be the following:
http://stackoverflow.com/questions/14765910/could-not-find-class-xxx-referenced-from-method-xxx-yyy

Or please let met know the details (logs, the version of android you use, how you installed the library).

@VaibhavAjayGupta
Copy link

I am getting the same error.
Steps that i followed are:-

  1. Download engine.io-client and socket.io-client jars from maven repository.
  2. Included them in the libs folder of my project.
  3. Project showing these jars in android private libraries which is ticked for use in java build path.
  4. Android target version is 18 min sdk is 8.

code i am using is

                    try {
            socket = IO.socket("http://192.168.1.3:3000/");
            socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {

                  @Override
                  public void call(Object... args) {
                    socket.emit("foo", "hi");
                    socket.disconnect();
                  }

                }).on("event", new Emitter.Listener() {

                  @Override
                  public void call(Object... args) {}

                }).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() {

                  @Override
                  public void call(Object... args) {}

                });
                socket.connect();
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

log says

06-11 16:09:23.912: W/dalvikvm(16631): VFY: unable to find class referenced in signature (Lorg/java_websocket/client/WebSocketClient;)
06-11 16:09:23.912: I/dalvikvm(16631): Could not find method org.java_websocket.client.WebSocketClient.close, referenced from method com.github.nkzawa.engineio.client.transports.WebSocket.doClose
06-11 16:09:23.912: W/dalvikvm(16631): VFY: unable to resolve virtual method 8794: Lorg/java_websocket/client/WebSocketClient;.close ()V
06-11 16:09:23.912: D/dalvikvm(16631): VFY: replacing opcode 0x6e at 0x0006
06-11 16:09:23.922: W/dalvikvm(16631): Unable to resolve superclass of Lcom/github/nkzawa/engineio/client/transports/WebSocket$1; (1449)
06-11 16:09:23.922: W/dalvikvm(16631): Link of class 'Lcom/github/nkzawa/engineio/client/transports/WebSocket$1;' failed
06-11 16:09:23.922: E/dalvikvm(16631): Could not find class 'com.github.nkzawa.engineio.client.transports.WebSocket$1', referenced from method com.github.nkzawa.engineio.client.transports.WebSocket.doOpen
06-11 16:09:23.922: W/dalvikvm(16631): VFY: unable to resolve new-instance 888 (Lcom/github/nkzawa/engineio/client/transports/WebSocket$1;) in Lcom/github/nkzawa/engineio/client/transports/WebSocket;
06-11 16:09:23.922: D/dalvikvm(16631): VFY: replacing opcode 0x22 at 0x001a
06-11 16:09:23.932: D/dalvikvm(16631): DexOpt: unable to opt direct call 0x225e at 0x27 in Lcom/github/nkzawa/engineio/client/transports/WebSocket;.doOpen
06-11 16:09:23.932: W/dalvikvm(16631): Unable to resolve superclass of Lcom/github/nkzawa/engineio/client/transports/WebSocket$1; (1449)
06-11 16:09:23.932: W/dalvikvm(16631): Link of class 'Lcom/github/nkzawa/engineio/client/transports/WebSocket$1;' failed
06-11 16:09:23.932: D/dalvikvm(16631): DexOpt: unable to opt direct call 0x16d8 at 0x2c in Lcom/github/nkzawa/engineio/client/transports/WebSocket;.doOpen
06-11 16:09:23.982: D/dalvikvm(16631): GC_CONCURRENT freed 228K, 13% free 9536K/10951K, paused 7ms+32ms, total 96ms
06-11 16:09:23.992: W/dalvikvm(16631): threadid=11: thread exiting with uncaught exception (group=0x411272a0)
06-11 16:09:24.012: E/AndroidRuntime(16631): FATAL EXCEPTION: Thread-1259
06-11 16:09:24.012: E/AndroidRuntime(16631): java.lang.NoClassDefFoundError: com.github.nkzawa.engineio.client.transports.WebSocket$1
06-11 16:09:24.012: E/AndroidRuntime(16631): at com.github.nkzawa.engineio.client.transports.WebSocket.doOpen(WebSocket.java:40)
06-11 16:09:24.012: E/AndroidRuntime(16631): at com.github.nkzawa.engineio.client.Transport$1.run(Transport.java:70)
06-11 16:09:24.012: E/AndroidRuntime(16631): at com.github.nkzawa.thread.EventThread.exec(EventThread.java:45)
06-11 16:09:24.012: E/AndroidRuntime(16631): at com.github.nkzawa.engineio.client.Transport.open(Transport.java:65)
06-11 16:09:24.012: E/AndroidRuntime(16631): at com.github.nkzawa.engineio.client.Socket.probe(Socket.java:411)
06-11 16:09:24.012: E/AndroidRuntime(16631): at com.github.nkzawa.engineio.client.Socket.onOpen(Socket.java:424)
06-11 16:09:24.012: E/AndroidRuntime(16631): at com.github.nkzawa.engineio.client.Socket.onHandshake(Socket.java:460)
06-11 16:09:24.012: E/AndroidRuntime(16631): at com.github.nkzawa.engineio.client.Socket.onPacket(Socket.java:437)
06-11 16:09:24.012: E/AndroidRuntime(16631): at com.github.nkzawa.engineio.client.Socket.access$800(Socket.java:25)
06-11 16:09:24.012: E/AndroidRuntime(16631): at com.github.nkzawa.engineio.client.Socket$5.call(Socket.java:251)
06-11 16:09:24.012: E/AndroidRuntime(16631): at com.github.nkzawa.emitter.Emitter.emit(Emitter.java:119)
06-11 16:09:24.012: E/AndroidRuntime(16631): at com.github.nkzawa.engineio.client.Transport.onPacket(Transport.java:118)
06-11 16:09:24.012: E/AndroidRuntime(16631): at com.github.nkzawa.engineio.client.transports.Polling.access$700(Polling.java:15)
06-11 16:09:24.012: E/AndroidRuntime(16631): at com.github.nkzawa.engineio.client.transports.Polling$2.call(Polling.java:122)
06-11 16:09:24.012: E/AndroidRuntime(16631): at com.github.nkzawa.engineio.parser.Parser.decodePayload(Parser.java:222)
06-11 16:09:24.012: E/AndroidRuntime(16631): at com.github.nkzawa.engineio.client.transports.Polling._onData(Polling.java:132)
06-11 16:09:24.012: E/AndroidRuntime(16631): at com.github.nkzawa.engineio.client.transports.Polling.onData(Polling.java:104)
06-11 16:09:24.012: E/AndroidRuntime(16631): at com.github.nkzawa.engineio.client.transports.PollingXHR$5$1.run(PollingXHR.java:112)
06-11 16:09:24.012: E/AndroidRuntime(16631): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
06-11 16:09:24.012: E/AndroidRuntime(16631): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
06-11 16:09:24.012: E/AndroidRuntime(16631): at java.lang.Thread.run(Thread.java:856)

@juanmiguelRuaDev
Copy link
Author

Mi issue happen like VaibhavAjayGupta but with java 7 and android sdk 19.
I had to downgrade the socket.io version in server from 1.0 to 0.9 and use another java client API.

@nkzawa
Copy link
Contributor

nkzawa commented Jun 12, 2014

@VaibhavAjayGupta Did you install org.java-websocke engine.io-client.java depends on?

@juanmiguelRuaDev
Copy link
Author

I've also installed the engine.io-client.jar dependency but don't run because "'Lcom/github/nkzawa/engineio/client/transports/WebSocket$1;' not found. Is strange because my source runs OK in a stand-alone java application.

@VaibhavAjayGupta
Copy link

After downloading all the dependency jars i am not getting the above errors but now i am getting this error

Could not find method org.json.JSONArray.remove, referenced from method com.github.nkzawa.socketio.client.Socket$4.run

@VaibhavAjayGupta
Copy link

@nkzawa thanks for the library. Awesome library 👍
Although it still shows the warning
Could not find method org.json.JSONArray.remove, referenced from method com.github.nkzawa.socketio.client.Socket$4.run

@juanmiguelRuaDev
At last got it working
jars required are:-

  1. socket.io-client-0.1.1(http://search.maven.org/remotecontent?filepath=com/github/nkzawa/socket.io-client/0.1.1/socket.io-client-0.1.1.jar)
  2. engine.io-client-0.2.1(http://search.maven.org/remotecontent?filepath=com/github/nkzawa/engine.io-client/0.2.1/engine.io-client-0.2.1.jar)
  3. WebSocket-1.3.0(http://search.maven.org/remotecontent?filepath=org/java-websocket/Java-WebSocket/1.3.0/Java-WebSocket-1.3.0.jar)

@nkzawa
Copy link
Contributor

nkzawa commented Jun 12, 2014

@VaibhavAjayGupta

I will fix JSONArray.remove issue, but please wait for a while. I'm a bit busy recently :(

@VaibhavAjayGupta
Copy link

sure

@juanmiguelRuaDev
Copy link
Author

Thank you very much @nkzawa and @VaibhavAjayGupta!. When I've time, I'll upgrade my current socket.io version in other branch.

@yurijmikhalevich
Copy link

@nkzawa This issue also affects on me. Thank you! Waiting for a fix.

@albertpeiro
Copy link

@VaibhavAjayGupta suggestion of adding the lib got mine fixed. Thank you! And thank you @nkzawa

@dragochristian
Copy link

This is the copy of my logcat:

07-06 16:13:55.767: E/AndroidRuntime(9040): FATAL EXCEPTION: Thread-900
07-06 16:13:55.767: E/AndroidRuntime(9040): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
07-06 16:13:55.767: E/AndroidRuntime(9040): at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6818)
07-06 16:13:55.767: E/AndroidRuntime(9040): at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:1080)
07-06 16:13:55.767: E/AndroidRuntime(9040): at android.view.View.requestLayout(View.java:16775)
07-06 16:13:55.767: E/AndroidRuntime(9040): at android.view.View.requestLayout(View.java:16775)
07-06 16:13:55.767: E/AndroidRuntime(9040): at android.view.View.requestLayout(View.java:16775)
07-06 16:13:55.767: E/AndroidRuntime(9040): at android.view.View.requestLayout(View.java:16775)
07-06 16:13:55.767: E/AndroidRuntime(9040): at android.view.View.requestLayout(View.java:16775)
07-06 16:13:55.767: E/AndroidRuntime(9040): at android.widget.TextView.checkForRelayout(TextView.java:7660)
07-06 16:13:55.767: E/AndroidRuntime(9040): at android.widget.TextView.setText(TextView.java:4446)
07-06 16:13:55.767: E/AndroidRuntime(9040): at android.widget.TextView.setText(TextView.java:4283)
07-06 16:13:55.767: E/AndroidRuntime(9040): at android.widget.TextView.setText(TextView.java:4258)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.christiandrago.syncronization.MainActivity$DownloadWebpageTask$1.call(MainActivity.java:180)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.emitter.Emitter.emit(Emitter.java:119)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.socketio.client.Socket.access$701(Socket.java:17)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.socketio.client.Socket$4.run(Socket.java:142)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.thread.EventThread.exec(EventThread.java:45)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.socketio.client.Socket.emit(Socket.java:138)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.socketio.client.Socket.onconnect(Socket.java:303)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.socketio.client.Socket.onpacket(Socket.java:230)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.socketio.client.Socket.access$400(Socket.java:17)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.socketio.client.Socket$2$1$3.call(Socket.java:90)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.emitter.Emitter.emit(Emitter.java:119)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.socketio.client.Manager.ondecoded(Manager.java:320)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.socketio.client.Manager.access$1100(Manager.java:20)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.socketio.client.Manager$3.call(Manager.java:294)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.emitter.Emitter.emit(Emitter.java:119)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.socketio.parser.Parser$Decoder.add(Parser.java:156)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.socketio.client.Manager.ondata(Manager.java:312)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.socketio.client.Manager.access$900(Manager.java:20)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.socketio.client.Manager$2.call(Manager.java:285)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.emitter.Emitter.emit(Emitter.java:119)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.engineio.client.Socket.onPacket(Socket.java:445)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.engineio.client.Socket.access$800(Socket.java:25)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.engineio.client.Socket$5.call(Socket.java:251)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.emitter.Emitter.emit(Emitter.java:119)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.engineio.client.Transport.onPacket(Transport.java:118)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.engineio.client.transports.Polling.access$700(Polling.java:15)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.engineio.client.transports.Polling$2.call(Polling.java:122)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.engineio.parser.Parser.decodePayload(Parser.java:222)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.engineio.client.transports.Polling._onData(Polling.java:132)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.engineio.client.transports.Polling.onData(Polling.java:104)
07-06 16:13:55.767: E/AndroidRuntime(9040): at com.github.nkzawa.engineio.client.transports.PollingXHR$5$1.run(PollingXHR.java:112)
07-06 16:13:55.767: E/AndroidRuntime(9040): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
07-06 16:13:55.767: E/AndroidRuntime(9040): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
07-06 16:13:55.767: E/AndroidRuntime(9040): at java.lang.Thread.run(Thread.java:841)

This is the code for the android application:
private class DownloadWebpageTask extends AsyncTask<String, String, String> {
@OverRide
//returns true if the tile was correctly downloaded
protected String doInBackground(String... urls) {
try {
socket = IO.socket("http://192.168.2.200:8080");
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {

  @Override
  public void call(Object... args) {
    //socket.emit("foo", "hi");
      logTV.setText("CONNECTED");
   // socket.disconnect();
  }

}).on("event", new Emitter.Listener() {

  @Override
  public void call(Object... args) {}

}).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() {

  @Override
  public void call(Object... args) {}

});
socket.connect();
} catch (URISyntaxException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

return "ciao";

}

and this is the code at server side:
// NODEJS SERVER WORKING
var http = require('http');

//set up the server
var server = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
});

//start server 130.237.238.191
//server.listen(8081, "192.168.1.42");
server.listen(8080, "192.168.2.200");

//bind the socket to the server
var io = require('socket.io')(server);

//var fs = require('fs');

//var io = require('socket.io').listen(8001);

io.sockets.on('connection', function (socket) {
console.log("android client connected at server side...");
//socket.emit('connected', "connection established");

/*socket.on('request', function (data) {
console.log(data);
socket.emit('response', {server: data['client']});

//fs.writeFile("c:/output.dat", data['client'], function(err) {
//  if(err) {
//      console.log(err);
//  } //else {
        //console.log("The client data was saved!");
    //}
//}); 

});*/
});
console.log('Server running');

I tried both the solution with and without AsyncTask and they gave me both the same errors.
Could anyone help me?

@albertpeiro
Copy link

@dragochristian Your error is pretty explicit: "Only the original thread that created a view hierarchy can touch its views."

The line: "logTV.setText("CONNECTED");" Cannot be called from a doInBackground thread. You should probably use the Handler class for that.

Read the Android docs on AsyncTask to learn why.

EDIT: btw, this is not related to socket.io. If unsure: StackOverflow.

@dragochristian
Copy link

I forgot to remove it after I copy and paste in the async task!
Thanks!!!

@nkzawa
Copy link
Contributor

nkzawa commented Jul 8, 2014

fixed #10

@nkzawa nkzawa closed this as completed Jul 8, 2014
@piovezan
Copy link

Just thought I'd mention that I'm clueless about why this issue ("Could not find method org.java_websocket.client.WebSocketClient., referenced from method com.github.nkzawa.engineio.client.transports.WebSocket$1.") happens.

I'm trying to solve it in a different way though so I can successfully debug the whole project (including socket.io-client, engine.io-client and Java-WebSocket library code) in Eclipse.

I have imported the projects into the IDE and followed http://stackoverflow.com/questions/14765910/could-not-find-class-xxx-referenced-from-method-xxx-yyy for each of them (i.e. added the generated target jar file to the project's Build Path, selected the file in the Order and Export tab and moved it to the top of the list).

It works for the first two projects but for Java-WebSocket it doesn't work. It only worked after I downloaded and included http://search.maven.org/remotecontent?filepath=org/java-websocket/Java-WebSocket/1.3.0/Java-WebSocket-1.3.0.jar in the libs folder as @VaibhavAjayGupta mentioned.

If anyone has an idea about what is going on, please let us know.

@saurabhsharma01
Copy link

Can you tell me steps to do WebSocket connection ....

@nitin105
Copy link

compile ('io.socket:engine.io-client:1.0.0') {
// excluding org.json which is provided by Android
exclude group: 'org.json', module: 'json'
}

its work for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants