0

我编写了一个从服务器获取数据的应用程序。我无法在我的应用程序的 4 活动中获取数据。我已经编写了一个单独的应用程序,它在第一个活动中获取并显示数据,但是当与我的应用程序集成时,它会强制关闭我的应用程序,我想在第 4 个活动中显示数据,我使用的是 2.2 Android 和 ksoap 2.5.4 . 我将发布我的代码和 LogCat 详细信息。

import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.EditText;


public class PatientUpdate extends Activity 
{
private static String SOAP_ACTION ="http://Something.com/GetPatientByID";
private static String NAMESPACE ="http://Something.com/";
private static String METHOD_NAME ="GetPatientByID";
private static String URL ="http://Something/service1.asmx";

EditText patname;
EditText dob;
EditText category;
EditText gender;
EditText addressline1;
EditText addressline2;
EditText addressline3;
EditText addressline4;
EditText phoneno;
EditText mobileno;
EditText RegistrationDate;
EditText validitydate;
EditText monthlyincome;



/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.updatepatient);

    patname = (EditText) findViewById(R.id.etpatname);
    dob = (EditText) findViewById(R.id.etpatdob);
    category = (EditText) findViewById(R.id.etcategory);
    gender = (EditText) findViewById(R.id.etgender);
    addressline1 = (EditText) findViewById(R.id.etaddline1);
    addressline2 = (EditText) findViewById(R.id.etaddline2);
    addressline3 = (EditText) findViewById(R.id.etaddline3);
    addressline4 = (EditText) findViewById(R.id.etaddline4);
    phoneno = (EditText) findViewById(R.id.etphno);
    mobileno = (EditText) findViewById(R.id.etmobileno);
    RegistrationDate = (EditText) findViewById(R.id.etregister);
    validitydate = (EditText) findViewById(R.id.etvalidity);
    monthlyincome = (EditText) findViewById(R.id.etmoninc);


  //Initialize soap request + add parameters
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    String date1="0019670";
    request.addProperty("patientID",date1);
    System.out.println("dfdjssf");


    // to receive the data from web service
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;//if the data is coming from .net service set it true
    envelope.setOutputSoapObject(request);

 // Make the soap call.
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    System.out.println("dfdjssf");
    try {

        //this is the actual part that will call the webservice
        androidHttpTransport.call(SOAP_ACTION, envelope);
        System.out.println("dfdjssf");
    } catch (Exception e) {
        e.printStackTrace(); 
    }

    // Get the SoapResult from the envelope body.parsethe data here     
    Object result;
    try {
        result = (Object)envelope.getResponse();
        Log.v("TAG", String.valueOf(result));

        //String Patientid=((SoapObject) result).getProperty(0).toString();

        //for salvation and name
        String Salvation=((SoapObject) result).getProperty(1).toString();
        String Name=((SoapObject) result).getProperty(2).toString();
        patname.setText(Salvation+"."+Name);

        //for DOB
        String Dob=((SoapObject) result).getProperty(3).toString();
        dob.setText(Dob);

        //for Gender
        String Gender=((SoapObject) result).getProperty(4).toString();
        gender.setText(Gender);

        //String bloodgroup=((SoapObject) result).getProperty(5).toString();
        //String wardno=((SoapObject) result).getProperty(6).toString();
        //String maritalstatus=((SoapObject)     result).getProperty(7).toString();

        //Address  line 1 2 3 4
        String addline1=((SoapObject) result).getProperty(9).toString();
        addressline1.setText(addline1);

        String addline2=((SoapObject) result).getProperty(10).toString();
        addressline2.setText(addline2);

        String addline3=((SoapObject) result).getProperty(11).toString();
        addressline3.setText(addline3);

        String addline4=((SoapObject) result).getProperty(12).toString();
        addressline3.setText(addline4);

        //for mobile and phone no
        String phno=((SoapObject) result).getProperty(15).toString();
        phoneno.setText(phno);

        String mobno=((SoapObject) result).getProperty(16).toString();
        mobileno.setText(mobno);

        //for category validity registration and monthly income
        String categ=((SoapObject) result).getProperty(22).toString();
        category.setText(categ);

        String regdate=((SoapObject) result).getProperty(23).toString();
        RegistrationDate.setText(regdate);

        String valid=((SoapObject) result).getProperty(24).toString();
        validitydate.setText(valid);

        String montinc=((SoapObject) result).getProperty(27).toString();
        monthlyincome.setText(montinc);


        Log.v("TAG", ((SoapObject) result).getProperty(0).toString());


    } 
    catch (SoapFault e) 
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // Log.v("TAG", String.valueOf(result));
   // SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
   // String strRes = result.toString();


    //if(result != null)
    //{



}
} 

输出是

10-24 10:30:04.766: INFO/ActivityManager(59): Starting activity: Intent { cmp=com.demo.patient/.PatientUpdate }
10-24 10:30:05.004: INFO/System.out(436): dfdjssf
10-24 10:30:05.045: INFO/System.out(436): dfdjssf
10-24 10:30:05.074: WARN/System.err(436): java.net.SocketException: Permission denied
10-24 10:30:05.084: WARN/System.err(436):     at org.apache.harmony.luni.platform.OSNetworkSystem.createStreamSocketImpl(Native Method)
10-24 10:30:05.084: WARN/System.err(436):     at org.apache.harmony.luni.platform.OSNetworkSystem.createStreamSocket(OSNetworkSystem.java:186)
10-24 10:30:05.084: WARN/System.err(436):     at org.apache.harmony.luni.net.PlainSocketImpl.create(PlainSocketImpl.java:265)
10-24 10:30:05.095: WARN/System.err(436):     at java.net.Socket.checkClosedAndCreate(Socket.java:873)
10-24 10:30:05.095: WARN/System.err(436):     at java.net.Socket.connect(Socket.java:1020)
10-24 10:30:05.095: WARN/System.err(436):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:62)
10-24 10:30:05.105: WARN/System.err(436):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:88)
10-24 10:30:05.105: WARN/System.err(436):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHTTPConnection(HttpURLConnectionImpl.java:927)
10-24 10:30:05.105: WARN/System.err(436):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:909)
10-24 10:30:05.105: WARN/System.err(436):     at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:75)
10-24 10:30:05.114: WARN/System.err(436):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:136)
10-24 10:30:05.114: WARN/System.err(436):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:90)
10-24 10:30:05.124: WARN/System.err(436):     at com.demo.patient.PatientUpdate.onCreate(PatientUpdate.java:77)
10-24 10:30:05.124: WARN/System.err(436):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-24 10:30:05.124: WARN/System.err(436):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
10-24 10:30:05.124: WARN/System.err(436):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
10-24 10:30:05.136: WARN/System.err(436):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
10-24 10:30:05.136: WARN/System.err(436):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
10-24 10:30:05.136: WARN/System.err(436):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-24 10:30:05.146: WARN/System.err(436):     at android.os.Looper.loop(Looper.java:123)
10-24 10:30:05.146: WARN/System.err(436):     at android.app.ActivityThread.main(ActivityThread.java:4627)
10-24 10:30:05.146: WARN/System.err(436):     at java.lang.reflect.Method.invokeNative(Native Method)
10-24 10:30:05.155: WARN/System.err(436):     at java.lang.reflect.Method.invoke(Method.java:521)
10-24 10:30:05.155: WARN/System.err(436):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-24 10:30:05.165: WARN/System.err(436):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-24 10:30:05.165: WARN/System.err(436):     at dalvik.system.NativeStart.main(Native Method)
10-24 10:30:05.174: DEBUG/AndroidRuntime(436): Shutting down VM
10-24 10:30:05.174: WARN/dalvikvm(436): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
10-24 10:30:05.195: ERROR/AndroidRuntime(436): FATAL EXCEPTION: main
10-24 10:30:05.195: ERROR/AndroidRuntime(436): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.demo.patient/com.demo.patient.PatientUpdate}: java.lang.NullPointerException
10-24 10:30:05.195: ERROR/AndroidRuntime(436):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
10-24 10:30:05.195: ERROR/AndroidRuntime(436):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
10-24 10:30:05.195: ERROR/AndroidRuntime(436):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
10-24 10:30:05.195: ERROR/AndroidRuntime(436):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
10-24 10:30:05.195: ERROR/AndroidRuntime(436):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-24 10:30:05.195: ERROR/AndroidRuntime(436):     at android.os.Looper.loop(Looper.java:123)
10-24 10:30:05.195: ERROR/AndroidRuntime(436):     at android.app.ActivityThread.main(ActivityThread.java:4627)
10-24 10:30:05.195: ERROR/AndroidRuntime(436):     at java.lang.reflect.Method.invokeNative(Native Method)
10-24 10:30:05.195: ERROR/AndroidRuntime(436):     at java.lang.reflect.Method.invoke(Method.java:521)
10-24 10:30:05.195: ERROR/AndroidRuntime(436):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-24 10:30:05.195: ERROR/AndroidRuntime(436):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-24 10:30:05.195: ERROR/AndroidRuntime(436):     at dalvik.system.NativeStart.main(Native Method)
10-24 10:30:05.195: ERROR/AndroidRuntime(436): Caused by: java.lang.NullPointerException
10-24 10:30:05.195: ERROR/AndroidRuntime(436):     at org.ksoap2.serialization.SoapSerializationEnvelope.getResponse(SoapSerializationEnvelope.java:552)
10-24 10:30:05.195: ERROR/AndroidRuntime(436):     at com.demo.patient.PatientUpdate.onCreate(PatientUpdate.java:86)
10-24 10:30:05.195: ERROR/AndroidRuntime(436):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-24 10:30:05.195: ERROR/AndroidRuntime(436):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
10-24 10:30:05.195: ERROR/AndroidRuntime(436):     ... 11 more
10-24 10:30:05.215: WARN/ActivityManager(59):   Force finishing activity com.demo.patient/.PatientUpdate
10-24 10:30:05.225: WARN/ActivityManager(59):   Force finishing activity com.demo.patient/.Login
10-24 10:30:05.766: WARN/ActivityManager(59): Activity pause timeout for HistoryRecord{450e4258 com.demo.patient/.PatientUpdate}
10-24 10:30:14.781: WARN/ActivityManager(59): Launch timeout has expired, giving up wake lock!
10-24 10:30:15.866: WARN/ActivityManager(59): Activity idle timeout for HistoryRecord{45002c48 com.demo.patient/.MyApp}
10-24 10:30:21.060: WARN/ActivityManager(59): Activity destroy timeout for HistoryRecord{450bab00 com.demo.patient/.Login}
10-24 10:30:21.060: WARN/ActivityManager(59): Activity destroy timeout for HistoryRecord{450e4258 com.demo.patient/.PatientUpdate}
10-24 10:30:27.940: DEBUG/SntpClient(59): request time failed: java.net.SocketException: Address family not supported by protocol
4

1 回答 1

1

您确定所有参数都已设置吗?

如果我没看错,你只有两个调试,对吗?这意味着它在这里失败:

    androidHttpTransport.call(SOAP_ACTION, envelope);

你能给你的肥皂 WS 真实网址吗?

于 2011-10-24T05:36:13.050 回答