Christine Bauers
- Forum-Beiträge: 1
15.10.2010, 12:14:24 via Website
15.10.2010 12:14:24 via Website
Hey Leute,
ich versuche mich gerade in Webservices in Verbindung mit Android einzuarbeiten und habe ein Tutorial gefunden. Ich folge den Anweisungen nehme exakt die gleiche jar, hier mal der Quellcode
und bekomme bei result ne NullPointerException. Hat jemand ne Idee, woran das liegen koennte?
Vielen Dank im Voraus und viele Gruesse
Asuka
ich versuche mich gerade in Webservices in Verbindung mit Android einzuarbeiten und habe ein Tutorial gefunden. Ich folge den Anweisungen nehme exakt die gleiche jar, hier mal der Quellcode
1// Soap object parameter initialization
2 // SOAP_ACTION: You build this from "NAMESPACE string" +
3 // "METHOD_NAME string"
4 // METHOD_NAME: User provided, you get this from the wsdl
5 // NAMESPACE: User provided, you get this from the wsdl
6 // URL: User provider, you get this from the wsdl
7 private static final String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit";
8 private static final String METHOD_NAME = "CelsiusToFahrenheit";
9 private static final String NAMESPACE = "http://tempuri.org/";
10 private static final String URL = "http://www.w3schools.com/webservices/tempconvert.asmx";
11 TextView tv;
12
13 public void onCreate(Bundle savedInstanceState) {
14 super.onCreate(savedInstanceState);
15 tv = (TextView) findViewById(R.id.text0);
16
17 SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
18 Request.addProperty("Celsius", "32");
19
20 // PART 4
21 // Create SOAP Envelope and serialize webservice XML object
22 SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
23 SoapEnvelope.VER11);
24 soapEnvelope.dotNet = true;
25 soapEnvelope.setOutputSoapObject(Request);
26 AndroidHttpTransport tns = new AndroidHttpTransport(URL);
27 try {
28 // PART 8
29 // Make the Web Service Call
30 tns.call(SOAP_ACTION, soapEnvelope);
31
32 // PART 9
33 // Extract the response from the Web Service Object
34 SoapPrimitive result = (SoapPrimitive) soapEnvelope.getResponse();
35
36 // Print out response
37 tv.setText("Quote Results: " + result);
38 } catch (Exception e)
39
40 {
41 e.printStackTrace();
42 }
43
44 }
2 // SOAP_ACTION: You build this from "NAMESPACE string" +
3 // "METHOD_NAME string"
4 // METHOD_NAME: User provided, you get this from the wsdl
5 // NAMESPACE: User provided, you get this from the wsdl
6 // URL: User provider, you get this from the wsdl
7 private static final String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit";
8 private static final String METHOD_NAME = "CelsiusToFahrenheit";
9 private static final String NAMESPACE = "http://tempuri.org/";
10 private static final String URL = "http://www.w3schools.com/webservices/tempconvert.asmx";
11 TextView tv;
12
13 public void onCreate(Bundle savedInstanceState) {
14 super.onCreate(savedInstanceState);
15 tv = (TextView) findViewById(R.id.text0);
16
17 SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
18 Request.addProperty("Celsius", "32");
19
20 // PART 4
21 // Create SOAP Envelope and serialize webservice XML object
22 SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
23 SoapEnvelope.VER11);
24 soapEnvelope.dotNet = true;
25 soapEnvelope.setOutputSoapObject(Request);
26 AndroidHttpTransport tns = new AndroidHttpTransport(URL);
27 try {
28 // PART 8
29 // Make the Web Service Call
30 tns.call(SOAP_ACTION, soapEnvelope);
31
32 // PART 9
33 // Extract the response from the Web Service Object
34 SoapPrimitive result = (SoapPrimitive) soapEnvelope.getResponse();
35
36 // Print out response
37 tv.setText("Quote Results: " + result);
38 } catch (Exception e)
39
40 {
41 e.printStackTrace();
42 }
43
44 }
und bekomme bei result ne NullPointerException. Hat jemand ne Idee, woran das liegen koennte?
Vielen Dank im Voraus und viele Gruesse
Asuka
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.