0

Just starting in Android dev, I would like to use Android Websockets code in my new project in Android Studio.

OS X 10.8.x, AS 0.4.0

I followed: How to import eclipse library project from github to android studio project?

Everything worked great until I tried to actually code. I pasted in (from the example):

List<BasicNameValuePair> extraHeaders = Arrays.asList(
    new BasicNameValuePair("Cookie", "session=abcd")
);

WebSocketClient client = new WebSocketClient(URI.create("wss://irccloud.com"), new WebSocketClient.Listener() {
    @Override
    public void onConnect() {
        Log.d(TAG, "Connected!");
    }

    @Override
    public void onMessage(String message) {
        Log.d(TAG, String.format("Got string message! %s", message));
    }

    @Override
    public void onMessage(byte[] data) {
        Log.d(TAG, String.format("Got binary message! %s", toHexString(data)));
    }

    @Override
    public void onDisconnect(int code, String reason) {
        Log.d(TAG, String.format("Disconnected! Code: %d Reason: %s", code, reason));
    }

    @Override
    public void onError(Exception error) {
        Log.e(TAG, "Error!", error);
    }

}, extraHeaders);

client.connect();

// Later… 
client.send("hello!");
client.send(new byte[] { 0xDE, 0xAD, 0xBE, 0xEF });
client.disconnect();

When I build/run the project, I get:

error: cannot find symbol class WebSocketClient

I think my question is: What is the import statement I should use?

How would I go about adding/using this code?

Community
  • 1
  • 1
nitsujri
  • 1,448
  • 2
  • 16
  • 29

2 Answers2

0

The auto importer was broken. Once I restarted Android Studio it showed I should put:

import com.codebutler.android_websockets.WebSocketClient;

As my import. Now I have a NullPointerException for a particular piece of code, but that's a different problem.

nitsujri
  • 1,448
  • 2
  • 16
  • 29
0

You ran into a bug that was fixed in Android Studio 0.4.3. I recommend you upgrade.

Scott Barta
  • 79,344
  • 24
  • 180
  • 163