weixin_44695125
这个柠檬有丶酸
2020-06-16 14:42
采纳率: 22.2%
浏览 141

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条回答 默认 最新

  • storm1979
    storm_huang 2020-06-16 16:36
    已采纳

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

    点赞 评论
  • weixin_41888261
    冻住的鱼 2020-06-18 09:15

    06-16 02:36:49.460: E/AndroidRuntime(891): Caused by: android.os.NetworkOnMainThreadException
    这里报错显示在主线程调用了网络请求,你创个子线程去调用就行了。

    点赞 评论

相关推荐