1

我已经在 andoird 清单页面中包含了 Internet 权限,但错误似乎仍然存在。我还在类似的代码中收到了一个未知的主机例外。请引导我完成!泰!:)

package name.id;

import android.app.Activity;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import org.ksoap2.*;
import org.ksoap2.serialization.*;
import org.ksoap2.transport.*;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class FirstPage extends Activity implements android.view.View.OnClickListener
{
    /** Called when the activity is first created. */

  TextView tv;
  Button bu;
  EditText et;

  private static final String SOAP_ACTION="http://lthed.com/GetFullNamefromUserID";
    private static final String METHOD_NAME="GetFullNamefromUserID";
    private static final String NAMESPACE="http://lthed.com";
    private static final String URL="http://vpwdvws09/services/DirectoryService.asmx";

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        et=(EditText) findViewById(R.id.editText1);
        tv=(TextView) findViewById(R.id.textView2);
        bu=(Button) findViewById(R.id.button1);
        bu.setOnClickListener((android.view.View.OnClickListener) this);
        tv.setText("");
    }

    public void onClick(View v)
    {           
        // creating the soap request and all its paramaters
        SoapObject request= new SoapObject(NAMESPACE, METHOD_NAME);
        //request.addProperty("ID","89385815");// hardcoding some random value
        //we can also take in a value in a var and pass it there


        //set soap envelope,set to dotnet and set output
        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        soapEnvelope.dotNet=true;
        soapEnvelope.setOutputSoapObject(request);

        HttpTransportSE obj = new HttpTransportSE(URL);
        //to make call to server
        try
        {
            obj.call(SOAP_ACTION,soapEnvelope);// in out parameter
            SoapPrimitive resultString=(SoapPrimitive)soapEnvelope.getResponse();
            //soapObject or soapString
            tv.setText("Status : " + resultString);
        }
        catch(Exception e)
        {
            tv.setText("Error : " + e.toString());
            //e.printStackTrace();
        }

}
}
4

3 回答 3

2

您是否在清单中添加了 Internet 权限:

<uses-permission android:name="android.permission.INTERNET"/>
于 2013-01-24T04:57:08.543 回答
1

由于 URL 中的错误而引发错误。URL 需要我的 IP 地址才能正常运行,而不是我提供的 URL,因为 Web 服务无法理解。

于 2013-03-06T05:32:24.367 回答
0

根据您使用的 KSOAP2 版本,错误可能会有所不同。

它推荐使用 KSOAP2 v3+ lib。

只需使用以下代码覆盖...

StrictMode.ThreadPolicy 策略 = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy);

并且还使用...

于 2014-08-03T09:32:32.733 回答