protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
beginConnect();
}
/* *
* hub链接
*/
private HubConnection conn=new HubConnection(HUB, this, new LongPollingTransport()) {
@Override
public void OnError(Exception exception) {
String a = "";
}
@Override
public void OnMessage(String message) {
String a = "";
}
@Override
public void OnStateChanged(StateBase oldState, StateBase newState) {
switch (newState.getState()){
case Connected:JSONArray jsonArray = new JSONArray();
jsonArray.put("b7f6ae28eaf44ef481929a6633fc34d2");
hub.Invoke("externalLogin", jsonArray, new HubInvokeCallback() {
@Override
public void OnResult(boolean succeeded, String response) {
Toast.makeText(MainActivity.this, response, Toast.LENGTH_LONG).show();
}
@Override
public void OnError(Exception ex) {
Toast.makeText(MainActivity.this, ex.toString(), Toast.LENGTH_LONG).show();
}
});
break;
case Connecting:String a = "";
break;
case Reconnecting: String a1 ="";break;
case Disconnected: String a2 ="";break;
case Disconnecting: String a3 = "";break;
}
}
};
private void beginConnect(){
try {
hub=conn.CreateHubProxy("ChatHub");
} catch (OperationApplicationException e) {
e.printStackTrace();
}
hub.On("LoginCallback", new HubOnDataCallback() {
@Override
public void OnReceived(JSONArray args) {
EditText chatText = (EditText) findViewById(R.id.edit);
Toast.makeText(MainActivity.this, args.toString(), Toast.LENGTH_LONG).show();
//chatText.setText(args.toString());
for (int i = 0; i < args.length(); i++) {
chatText.append(args.opt(i).toString());
}
}
});
conn.Start();
}
报的错误
12-11 14:01:09.602 25809-25809/com.example.fenghao.test W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x27fdad88)
12-11 14:01:09.602 25809-25809/com.example.test E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.test, PID: 25809
java.lang.NullPointerException
at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116)
at org.json.JSONTokener.nextValue(JSONTokener.java:94)
at org.json.JSONObject.(JSONObject.java:155)
at org.json.JSONObject.(JSONObject.java:172)
at com.zsoft.signala.transport.longpolling.JSONHelper.ToJSONObject(JSONHelper.java:12)
at com.zsoft.signala.transport.longpolling.ConnectedState$2.onComplete(ConnectedState.java:120)
at com.turbomanage.httpclient.android.DoHttpRequestTask.onPostExecute(DoHttpRequestTask.java:56)
at com.turbomanage.httpclient.android.DoHttpRequestTask.onPostExecute(DoHttpRequestTask.java:1)
at android.os.AsyncTask.finish(AsyncTask.java:632)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5098)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:780)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:596)
at dalvik.system.NativeStart.main(Native Method)
12-11 14:01:09.622 25809-25845/com.example.test W/System.err﹕ java.net.ConnectException: failed to connect to /123.56.130.232 (port 8089) after 1000ms: connect failed: ENETUNREACH (Network is unreachable)
12-11 14:01:09.622 25809-25845/com.example.test W/System.err﹕ at libcore.io.IoBridge.connect(IoBridge.java:114)
12-11 14:01:09.622 25809-25845/com.example.test W/System.err﹕ at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
12-11 14:01:09.622 25809-25845/com.example.test W/System.err﹕ at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:460)
12-11 14:01:09.622 25809-25845/com.example.test W/System.err﹕ at java.net.Socket.connect(Socket.java:833)
12-11 14:01:09.622 25809-25845/com.example.test W/System.err﹕ at com.android.okhttp.internal.Platform.connectSocket(Platform.java:131)
12-11 14:01:09.622 25809-25845/com.example.test W/System.err﹕ at com.android.okhttp.Connection.connect(Connection.java:101)
12-11 14:01:09.622 25809-25845/com.example.test W/System.err﹕ at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:294)
12-11 14:01:09.622 25809-25845/com.example.test W/System.err﹕ at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
12-11 14:01:09.622 25809-25845/com.example.test W/System.err﹕ at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
12-11 14:01:09.622 25809-25845/com.example.test W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
12-11 14:01:09.622 25809-25845/com.example.test W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89)
12-11 14:01:09.622 25809-25845/com.example.test W/System.err﹕ at com.turbomanage.httpclient.AbstractHttpClient.doHttpMethod(AbstractHttpClient.java:213)
12-11 14:01:09.622 25809-25845/com.example.test W/System.err﹕ at com.turbomanage.httpclient.AsyncHttpClient.tryMany(AsyncHttpClient.java:185)
12-11 14:01:09.622 25809-25845/com.example.test W/System.err﹕ at com.turbomanage.httpclient.android.DoHttpRequestTask.doInBackground(DoHttpRequestTask.java:40)
12-11 14:01:09.622 25809-25845/com.example.test W/System.err﹕ at com.turbomanage.httpclient.android.DoHttpRequestTask.doInBackground(DoHttpRequestTask.java:1)
12-11 14:01:09.622 25809-25845/com.example.test W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:288)
12-11 14:01:09.622 25809-25845/com.example.test W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
12-11 14:01:09.622 25809-25845/com.example.test W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
12-11 14:01:09.622 25809-25845/com.example.test W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
12-11 14:01:09.622 25809-25845/com.example.test W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
12-11 14:01:09.622 25809-25845/com.example.test W/System.err﹕ Caused by: libcore.io.ErrnoException: connect failed: ENETUNREACH (Network is unreachable)
12-11 14:01:09.632 25809-25845/com.example.test W/System.err﹕ at libcore.io.Posix.connect(Native Method)
12-11 14:01:09.632 25809-25845/com.example.test W/System.err﹕ at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
12-11 14:01:09.632 25809-25845/com.example.test W/System.err﹕ at libcore.io.IoBridge.connectErrno(IoBridge.java:144)
12-11 14:01:09.632 25809-25845/com.example.test W/System.err﹕ at libcore.io.IoBridge.connect(IoBridge.java:112)
12-11 14:01:09.632 25809-25845/com.example.test W/System.err﹕ ... 19 more
12-11 14:01:09.632 25809-25845/com.example.test W/System.err﹕ com.turbomanage.httpclient.HttpRequestException: java.net.ConnectException: failed to connect to /123.56.130.232 (port 8089) after 1000ms: connect failed: ENETUNREACH (Network is unreachable)
12-11 14:01:09.632 25809-25845/com.example.test W/System.err﹕ at com.turbomanage.httpclient.AbstractHttpClient.doHttpMethod(AbstractHttpClient.java:235)
12-11 14:01:09.632 25809-25845/com.example.test W/System.err﹕ at com.turbomanage.httpclient.AsyncHttpClient.tryMany(AsyncHttpClient.java:185)
12-11 14:01:09.632 25809-25845/com.example.test W/System.err﹕ at com.turbomanage.httpclient.android.DoHttpRequestTask.doInBackground(DoHttpRequestTask.java:40)
12-11 14:01:09.632 25809-25845/com.example.test W/System.err﹕ at com.turbomanage.httpclient.android.DoHttpRequestTask.doInBackground(DoHttpRequestTask.java:1)
12-11 14:01:09.632 25809-25845/com.example.test W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:288)
12-11 14:01:09.632 25809-25845/com.example.test W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
12-11 14:01:09.632 25809-25845/com.example.test W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
12-11 14:01:09.632 25809-25845/com.example.test W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
12-11 14:01:09.632 25809-25845/com.example.test W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
12-11 14:01:09.632 25809-25845/com.example.test W/System.err﹕ Caused by: java.net.ConnectException: failed to connect to /123.56.130.232 (port 8089) after 1000ms: connect failed: ENETUNREACH (Network is unreachable)
12-11 14:01:09.632 25809-25845/com.example.test W/System.err﹕ at libcore.io.IoBridge.connect(IoBridge.java:114)
12-11 14:01:09.632 25809-25845/com.example.test W/System.err﹕ at java.ne
应该是你内存不足或配置不够好无法正常运行,可以试试刷下别的系统再运行;实在不行就是硬件配置不够。希望能帮到你!
答案来源于网络
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。