青衣画白扇 2020-06-16 14:42 采纳率: 25%
浏览 152
已采纳

Android调用java 写的webservices 报错

private EditText nametex,passwordtex;
     @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);//去除图标
            setContentView(R.layout.activity_main);
            nametex=(EditText) findViewById(R.id.name);
            passwordtex=(EditText) findViewById(R.id.password);
        }

    //确定按钮
     public void btnOk(View view) throws IOException, XmlPullParserException {
     String names = nametex.getText().toString();
     String pwds = passwordtex.getText().toString();
     if (TextUtils.isEmpty(names) || TextUtils.isEmpty(pwds)) {
     Toast.makeText(this, "用户名和密码不能为空", Toast.LENGTH_LONG).show();
     }else{
                // 命名空间
                String nameSpace = "http://Impi.services.jksd.com/";
                // 调用的方法名称
                String methodName = "Account_isPasswordCorrect";
               // String action=nameSpace+methodName;
                // SOAP Action
                SoapObject request = new SoapObject(nameSpace, methodName);
                request.addProperty("Account_Name", names);
                request.addProperty("Account_Password", pwds);
                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                envelope.dotNet = false;//.net的接口为true
                envelope.bodyOut = request;
                envelope.setOutputSoapObject(request);
                envelope.encodingStyle="UTF-8";
                HttpTransportSE transport = new HttpTransportSE("http://192.168.2.181:19999/webservices?wsdl");// wsdl文档
                    // 调用WebService
                    transport.call(null, envelope);
                System.err.println(envelope.getResponse().toString());
     }

     }

报错

06-16 02:36:49.390: D/AndroidRuntime(891): Shutting down VM
06-16 02:36:49.390: W/dalvikvm(891): threadid=1: thread exiting with uncaught exception (group=0xb3a82b90)
06-16 02:36:49.460: E/AndroidRuntime(891): FATAL EXCEPTION: main
06-16 02:36:49.460: E/AndroidRuntime(891): Process: com.jksd.app, PID: 891
06-16 02:36:49.460: E/AndroidRuntime(891): java.lang.IllegalStateException: Could not execute method of the activity
06-16 02:36:49.460: E/AndroidRuntime(891):  at android.view.View$1.onClick(View.java:3814)
06-16 02:36:49.460: E/AndroidRuntime(891):  at android.view.View.performClick(View.java:4424)
06-16 02:36:49.460: E/AndroidRuntime(891):  at android.view.View$PerformClick.run(View.java:18383)
06-16 02:36:49.460: E/AndroidRuntime(891):  at android.os.Handler.handleCallback(Handler.java:733)
06-16 02:36:49.460: E/AndroidRuntime(891):  at android.os.Handler.dispatchMessage(Handler.java:95)
06-16 02:36:49.460: E/AndroidRuntime(891):  at android.os.Looper.loop(Looper.java:137)
06-16 02:36:49.460: E/AndroidRuntime(891):  at android.app.ActivityThread.main(ActivityThread.java:4998)
06-16 02:36:49.460: E/AndroidRuntime(891):  at java.lang.reflect.Method.invokeNative(Native Method)
06-16 02:36:49.460: E/AndroidRuntime(891):  at java.lang.reflect.Method.invoke(Method.java:515)
06-16 02:36:49.460: E/AndroidRuntime(891):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
06-16 02:36:49.460: E/AndroidRuntime(891):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
06-16 02:36:49.460: E/AndroidRuntime(891):  at dalvik.system.NativeStart.main(Native Method)
06-16 02:36:49.460: E/AndroidRuntime(891): Caused by: java.lang.reflect.InvocationTargetException
06-16 02:36:49.460: E/AndroidRuntime(891):  at java.lang.reflect.Method.invokeNative(Native Method)
06-16 02:36:49.460: E/AndroidRuntime(891):  at java.lang.reflect.Method.invoke(Method.java:515)
06-16 02:36:49.460: E/AndroidRuntime(891):  at android.view.View$1.onClick(View.java:3809)
06-16 02:36:49.460: E/AndroidRuntime(891):  ... 11 more
06-16 02:36:49.460: E/AndroidRuntime(891): Caused by: android.os.NetworkOnMainThreadException
06-16 02:36:49.460: E/AndroidRuntime(891):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1145)
06-16 02:36:49.460: E/AndroidRuntime(891):  at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
06-16 02:36:49.460: E/AndroidRuntime(891):  at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
06-16 02:36:49.460: E/AndroidRuntime(891):  at libcore.io.IoBridge.connect(IoBridge.java:112)
06-16 02:36:49.460: E/AndroidRuntime(891):  at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
06-16 02:36:49.460: E/AndroidRuntime(891):  at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
06-16 02:36:49.460: E/AndroidRuntime(891):  at java.net.Socket.connect(Socket.java:843)
06-16 02:36:49.460: E/AndroidRuntime(891):  at com.android.okhttp.internal.Platform.connectSocket(Platform.java:131)
06-16 02:36:49.460: E/AndroidRuntime(891):  at com.android.okhttp.Connection.connect(Connection.java:101)
06-16 02:36:49.460: E/AndroidRuntime(891):  at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:294)
06-16 02:36:49.460: E/AndroidRuntime(891):  at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
06-16 02:36:49.460: E/AndroidRuntime(891):  at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
06-16 02:36:49.460: E/AndroidRuntime(891):  at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
06-16 02:36:49.460: E/AndroidRuntime(891):  at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89)
06-16 02:36:49.460: E/AndroidRuntime(891):  at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:75)
06-16 02:36:49.460: E/AndroidRuntime(891):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:136)
06-16 02:36:49.460: E/AndroidRuntime(891):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:90)
06-16 02:36:49.460: E/AndroidRuntime(891):  at com.jksd.app.MainActivity.btnOk(MainActivity.java:55)
06-16 02:36:49.460: E/AndroidRuntime(891):  ... 14 more
06-16 02:36:49.530: D/dalvikvm(891): GC_FOR_ALLOC freed 253K, 10% free 3027K/3360K, paused 57ms, total 60ms

有没有Android的大佬帮忙看看!!!

  • 写回答

2条回答 默认 最新

  • storm_huang 2020-06-16 16:36
    关注

    网络请求位置问题,不能在主进程发起http请求。
    可以参考一下:https://blog.csdn.net/qq_29477223/article/details/81027716

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 vb6.0截取当前窗体保存为jpg文件
  • ¥20 苹果手机不使用大疆sdk怎么获取遥控器控制信息或如何接入大疆sdk并且成功上架sdk
  • ¥20 woocommerce 注册按键重定向
  • ¥100 求书法图像文字切割代码
  • ¥15 同一个波形探测距离不同的目标,为什么fft之后得到的频谱图会发生移动,不应该时移不改变幅度谱吗(标签-matlab)(相关搜索:matlab仿真)
  • ¥15 Proteus仿真程序只能执行一次
  • ¥15 语音识别websocket报错
  • ¥15 激光器,引脚问题,无法处理
  • ¥20 求写一份!只提交Mapper映射文件 如:UsersMapper.xml
  • ¥15 CH340C串口模块无法被识别