java.net.SocketException异常:地​​址族不支持的协议 [英] java.net.SocketException: Address family not supported by protocol

查看:140
本文介绍了java.net.SocketException异常:地​​址族不支持的协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在android的我收到以下错误:

in android i am getting the following error :

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

我的code尝试使用web服务:

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);

和异常messege为NULL。 所有传递的参数是correct.AndroidManifest.xml也行。

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

在登录猫我收到此异常: java.net.SocketException异常:地​​址族不支持的协议

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

推荐答案

尝试添加到您的Andr​​oidManifest.xml还有:

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();
       }

这篇关于java.net.SocketException异常:地​​址族不支持的协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆