java.net.SocketException:协议不支持地址族

发布于 2024-12-11 04:18:16 字数 3351 浏览 0 评论 0原文

在 android 中我收到以下错误:

NativeStart.main(String[]) 行:不可用[本机方法]

我的代码正在尝试使用 Web 服务:

import java.io.IOException;

import android.app.Activity;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import android.app.*;
import android.content.Context;
import android.os.*;
import android.widget.TextView;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;


public class Project_InvokeServiceActivity extends Activity {
    /** Called when the activity is first created. */

     private static final String SOAP_ACTION = "http://tempuri.org/userg";

        private static final String METHOD_NAME = "userg";

        private static final String NAMESPACE = "http://tempuri.org/";
        private static final String URL = "https://amaman.NewService/Permissions.asmx";
       // TextView tv;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       // tv=(TextView)findViewById(R.id.text1);
       // call();

             TextView tv = new TextView(this);




                 SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
                 request.addProperty("username", "222222");

            request.addProperty("ID", "123");



            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;

            envelope.setOutputSoapObject(request);

            setContentView(tv);

            try { HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            tv.setText("t");

            ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo netInfo = cm.getActiveNetworkInfo();

            if (netInfo != null && netInfo.isConnectedOrConnecting()) {
                tv.setText("connected"+netInfo.getExtraInfo());
            }
            else{
            tv.setText("not conn");
            }


            try{


                androidHttpTransport.call(SOAP_ACTION, envelope);

                tv.setText("t1");
            }catch(Exception e){
                //tv.setText(e.getClass().getName());
                }



           // tv.setText("inside2");


            Object result = (Object)envelope.getResponse();


    } catch (Exception e2) {
        // TODO Auto-generated catch block
        //e.printStackTrace();
        TextView tv5 = new TextView(this);
        //tv3.setText(e1.getMessage());
       // tv.setText(result.toString());

        tv5.setText("exception"+e2.getClass()+"xxx");
        setContentView(tv);
    }

           // tv.setText(result.toString());
          //  tv.setText("inside");

          //  setContentView(tv);




    }

我的程序正在连接到互联网....但它在下面的行中抛出异常:

androidHttpTransport.call(SOAP_ACTION, envelope);

并且异常消息为 NULL。 传递的参数都是正确的。AndroidManifest.xml也没有问题。

在 Log Cat 中我收到此异常: java.net.SocketException:协议不支持地址族

in android I am getting the following error:

NativeStart.main(String[]) line: not available [native method]

my code is trying to use webservices:

import java.io.IOException;

import android.app.Activity;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import android.app.*;
import android.content.Context;
import android.os.*;
import android.widget.TextView;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;


public class Project_InvokeServiceActivity extends Activity {
    /** Called when the activity is first created. */

     private static final String SOAP_ACTION = "http://tempuri.org/userg";

        private static final String METHOD_NAME = "userg";

        private static final String NAMESPACE = "http://tempuri.org/";
        private static final String URL = "https://amaman.NewService/Permissions.asmx";
       // TextView tv;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       // tv=(TextView)findViewById(R.id.text1);
       // call();

             TextView tv = new TextView(this);




                 SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
                 request.addProperty("username", "222222");

            request.addProperty("ID", "123");



            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;

            envelope.setOutputSoapObject(request);

            setContentView(tv);

            try { HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            tv.setText("t");

            ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo netInfo = cm.getActiveNetworkInfo();

            if (netInfo != null && netInfo.isConnectedOrConnecting()) {
                tv.setText("connected"+netInfo.getExtraInfo());
            }
            else{
            tv.setText("not conn");
            }


            try{


                androidHttpTransport.call(SOAP_ACTION, envelope);

                tv.setText("t1");
            }catch(Exception e){
                //tv.setText(e.getClass().getName());
                }



           // tv.setText("inside2");


            Object result = (Object)envelope.getResponse();


    } catch (Exception e2) {
        // TODO Auto-generated catch block
        //e.printStackTrace();
        TextView tv5 = new TextView(this);
        //tv3.setText(e1.getMessage());
       // tv.setText(result.toString());

        tv5.setText("exception"+e2.getClass()+"xxx");
        setContentView(tv);
    }

           // tv.setText(result.toString());
          //  tv.setText("inside");

          //  setContentView(tv);




    }

my program is connecting to internet....but it is throwing exception in the line below:

androidHttpTransport.call(SOAP_ACTION, envelope);

and exception messege is NULL.
All the parameter passed are correct.AndroidManifest.xml is also ok.

In Log Cat i am getting this exception:
java.net.SocketException: Address family not supported by protocol

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最丧也最甜 2024-12-18 04:18:16

尝试将其添加到您的 AndroidManifest.xml 中:

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

您还需要捕获此异常:

 catch(SocketException ex)
       {
         Log.e("Error : " , "Error on soapPrimitiveData() " + ex.getMessage());
           ex.printStackTrace();
       }

Try adding this to your AndroidManifest.xml as well:

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

You also need to catch this Exception:

 catch(SocketException ex)
       {
         Log.e("Error : " , "Error on soapPrimitiveData() " + ex.getMessage());
           ex.printStackTrace();
       }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文