Android System.error JSONRPCException: IO 错误

Posted

技术标签:

【中文标题】Android System.error JSONRPCException: IO 错误【英文标题】:Android System.error JSONRPCException: IO error 【发布时间】:2012-07-10 21:10:55 【问题描述】:

我正在使用来自http://jsonrpcphp.org/?page=example&lang=en 的 JSON-RPC PHP 创建 php jsonrpc 作为服务器

android-json-rpc 作为 android http://code.google.com/p/android-json-rpc/ 的客户端

我的服务器没问题,我可以从 php 调用它,但是当我从 android 调用它时,它给了我系统错误,我无法解决它,任何人都可以帮忙吗?

07-10 23:36:01.685: W/System.err(457): org.alexd.jsonrpc.JSONRPCException: IO error
07-10 23:36:01.685: W/System.err(457):  at org.alexd.jsonrpc.JSONRPCHttpClient.doJSONRequest(JSONRPCHttpClient.java:142)
07-10 23:36:01.695: W/System.err(457):  at org.alexd.jsonrpc.JSONRPCClient.doRequest(JSONRPCClient.java:77)
07-10 23:36:01.695: W/System.err(457):  at org.alexd.jsonrpc.JSONRPCClient.callJSONArray(JSONRPCClient.java:528)
07-10 23:36:01.695: W/System.err(457):  at com.afaqy.afaqytemp.AfaqyTempActivity.login(AfaqyTempActivity.java:63)
07-10 23:36:01.695: W/System.err(457):  at com.afaqy.afaqytemp.AfaqyTempActivity.access$0(AfaqyTempActivity.java:41)
07-10 23:36:01.695: W/System.err(457):  at com.afaqy.afaqytemp.AfaqyTempActivity$1.onClick(AfaqyTempActivity.java:34)
07-10 23:36:01.695: W/System.err(457):  at android.view.View.performClick(View.java:2408)
07-10 23:36:01.695: W/System.err(457):  at android.view.View$PerformClick.run(View.java:8816)
07-10 23:36:01.695: W/System.err(457):  at android.os.Handler.handleCallback(Handler.java:587)
07-10 23:36:01.695: W/System.err(457):  at android.os.Handler.dispatchMessage(Handler.java:92)
07-10 23:36:01.705: W/System.err(457):  at android.os.Looper.loop(Looper.java:123)
07-10 23:36:01.705: W/System.err(457):  at android.app.ActivityThread.main(ActivityThread.java:4627)
07-10 23:36:01.705: W/System.err(457):  at java.lang.reflect.Method.invokeNative(Native Method)
07-10 23:36:01.705: W/System.err(457):  at java.lang.reflect.Method.invoke(Method.java:521)
07-10 23:36:01.705: W/System.err(457):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-10 23:36:01.705: W/System.err(457):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-10 23:36:01.705: W/System.err(457):  at dalvik.system.NativeStart.main(Native Method)
07-10 23:36:01.705: W/System.err(457): Caused by: java.net.SocketException: Permission denied
07-10 23:36:01.715: W/System.err(457):  at org.apache.harmony.luni.platform.OSNetworkSystem.createStreamSocketImpl(Native Method)
07-10 23:36:01.715: W/System.err(457):  at org.apache.harmony.luni.platform.OSNetworkSystem.createStreamSocket(OSNetworkSystem.java:186)
07-10 23:36:01.715: W/System.err(457):  at org.apache.harmony.luni.net.PlainSocketImpl.create(PlainSocketImpl.java:265)
07-10 23:36:01.715: W/System.err(457):  at java.net.Socket.checkClosedAndCreate(Socket.java:873)
07-10 23:36:01.715: W/System.err(457):  at java.net.Socket.connect(Socket.java:1020)
07-10 23:36:01.715: W/System.err(457):  at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
07-10 23:36:01.715: W/System.err(457):  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143)
07-10 23:36:01.715: W/System.err(457):  at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
07-10 23:36:01.715: W/System.err(457):  at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
07-10 23:36:01.715: W/System.err(457):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
07-10 23:36:01.715: W/System.err(457):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
07-10 23:36:01.715: W/System.err(457):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
07-10 23:36:01.725: W/System.err(457):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
07-10 23:36:01.725: W/System.err(457):  at org.alexd.jsonrpc.JSONRPCHttpClient.doJSONRequest(JSONRPCHttpClient.java:110)
07-10 23:36:01.725: W/System.err(457):  ... 16 more

我的安卓代码是

        JSONRPCClient clientrpc = JSONRPCClient.create("http://192.168.1.102/server.php",JSONRPCParams.Versions.VERSION_2);
      clientrpc.setConnectionTimeout(2000);

      clientrpc.setSoTimeout(2000);
        try 
        
          JSONArray stringdata = clientrpc.callJSONArray("login","demo","123456");

          try 
            Toast.makeText(getApplicationContext(),
                        stringdata.getString(1), Toast.LENGTH_SHORT)
                        .show();
         catch (JSONException e) 
            // TODO Auto-generated catch block
            //  e.printStackTrace();
            Toast.makeText(getApplicationContext(),
                    "ERROR ON CHECKLOGIN", Toast.LENGTH_SHORT)
                    .show();
        

        
        catch (JSONRPCException e)
        
          e.printStackTrace();
            Toast.makeText(getApplicationContext(),
                    "Error ON server connection", Toast.LENGTH_SHORT)
                    .show();
        

json 输出的数组

    [Logedin] => 1
    [drivers] => Array
        (

   
    [objects] => Array
        (

   

【问题讨论】:

感谢它在我将 放在 AndroidManifest.xml 上后工作,因为这个错误是由于套接字 permation 而发生的 【参考方案1】:

谢谢,我放了之后就可以了

<uses-permission android:name="android.permission.INTERNET" />

AndroidManifest.xml 上,因为此错误是由于套接字权限而发生的。

【讨论】:

以上是关于Android System.error JSONRPCException: IO 错误的主要内容,如果未能解决你的问题,请参考以下文章

boost::system::error_code 产生错误 158 未知

Exclusive_scan 中的 CUDA 推力推力::system::system_error

Python报RuntimeError NCCL Error 2 unhandled system error

Error code: 205 System Error(-1)

Python报RuntimeError NCCL Error 2 unhandled system error

Python报RuntimeError NCCL Error 2 unhandled system error