0

I can't init the InetSocketAddress, the exception is thrown when create InetSocketAddress. I run my app in android 2.3.4.

    Log.i("Test", "Hien Connect host="+_host+" & port="+_port);
try 
{
    _socket_channel = SocketChannel.open();
    _socket_channel.configureBlocking(false);
            Log.i("Test", "Hien Connect 34");
    //InetSocketAddress socketAddress = new InetSocketAddress(InetAddress.getByAddress(b), _port);
    _socket_channel.connect(new InetSocketAddress(_host, _port));
    //_socket_channel.connect(socketAddress);

The output is below. When I run this app in android 4.1.2, the app can connet to server successfully. How can I use InitSocketAddress in android 2.3.3 and 2.3.4 ?

06-07 16:32:16.695: I/Pixma(16303): Hien Connect 34
06-07 16:32:16.780: E/dalvikvm(16303): Class lookup Ljava/lang/NullPointerException; attempted while exception Ljava/net/UnknownHostException; pending
06-07 16:32:16.780: I/dalvikvm(16303): DALVIK THREADS:
06-07 16:32:16.780: I/dalvikvm(16303): (mutexes: tll=0 tsl=0 tscl=0 ghl=0 hwl=0 hwll=0)
06-07 16:32:16.780: I/dalvikvm(16303): "main" prio=5 tid=1 RUNNABLE
06-07 16:32:16.780: I/dalvikvm(16303):   | group="main" sCount=0 dsCount=0 obj=0x400281b8 self=0xcec0
06-07 16:32:16.780: I/dalvikvm(16303):   | sysTid=16303 nice=0 sched=0/0 cgrp=default handle=-1345006496
06-07 16:32:16.780: I/dalvikvm(16303):   | schedstat=( 169151824 239494686 1029 )
06-07 16:32:16.780: I/dalvikvm(16303):   at java.net.InetAddress.getHostName(InetAddress.java:~355)
06-07 16:32:16.780: I/dalvikvm(16303):   at java.net.InetSocketAddress.<init>(InetSocketAddress.java:69)
06-07 16:32:16.780: I/DEBUG(13679): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-07 16:32:16.780: I/DEBUG(13679): Build fingerprint: 'samsung/GT-I9100/GT-I9100:2.3.3/GINGERBREAD/DXKG3:user/release-keys'
4

2 回答 2

0

我找到了解决方案,当我在 MainActivity 中创建套接字并且 MainRenderer 中的另一个线程从 C 调用它时,这是我的错误,它使上述错误发生。当我在 MainRenderer 中创建套接字时,错误解决了!谢谢你的帮助 !

于 2013-06-12T03:47:48.320 回答
-1

尝试这个

    InetAddress serverAddr = InetAddress.getByName("120.119.112.168");
    SocketAddress sc_add= new InetSocketAddress(serverAddr,1234);
    _socket_channel.connect(sc_add);
于 2013-06-07T13:39:40.410 回答