0

This coding i got from here. I get error in log cat view like the one i mentioned after the coding.. please provide me some suggestion to clear this..

package com.example.firstws;



import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;

public class Firstws extends Activity {
    /** Called when the activity is first created. */
    private static final String SOAP_ACTION="http://tempuri.org/CelsiusToFarenheit";
    private static final String METHOD_NAME="CelsiusToFarenheit";
    private static final String NAMESPACE="http://tempuri.org/";
    private static final String URL="http://www.w3schools.com/webservices/tempconvert.asmx";
    TextView tv=(TextView)findViewById(R.id.textView1);
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        SoapObject Request=new SoapObject(NAMESPACE,METHOD_NAME);
        Request.addProperty("Celsius","32");
        SoapSerializationEnvelope soapEnvelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
        soapEnvelope.dotNet=true;
        soapEnvelope.setOutputSoapObject(Request);
        AndroidHttpTransport aht=new AndroidHttpTransport(URL);
        try
        {
            aht.call(SOAP_ACTION, soapEnvelope);
            SoapPrimitive resultString=(SoapPrimitive)soapEnvelope.getResponse();
            tv.setText("Status:"+resultString);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        }

    }

Error:

java.lang.runtime exception: unable to instantiate the activity componentinfo{com.example.firstws/com.example.firstws.Firstws}: java.lang.NullpointerException
1
  • Welcome. can you format the code please? Your logs indicate a NullPointer Exception, but the logs should tell what line #. Go to that line and go from there. Commented Jun 3, 2011 at 12:02

1 Answer 1

1

You can't do this TextView tv=(TextView)findViewById(R.id.textView1); before you call setContentView(). Since no layout has been set at the time of the class' initialization, it will fail. Move the assignment after your call to setContentView().

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks dmon. But now also i'm not getting the expected result. A warning is being showed like "java.net.SocketException: Permission denied(may be missing internet permission)"
You need to add the internet permission to your AndroidManifest.xml file: <uses-permission android:name="android.permission.INTERNET" />.
Still same warning is being showed dmon. Please tell where to place the code line that you written in android manifest file. and also i'm getting java null pointer exception in console while running the project.
I've placed it rightly and while running the project, below mentioned is being showed in logcat "WARN/System.err(1929): SoapFault - faultcode: 'soap:Client' faultstring: 'Server did not recognize the value of HTTP Header SOAPAction: tempuri.org/CelsiusToFarenheit.' faultactor: 'null' detail: org.kxml2.kdom.Node@44eabe90"
put the <uses-permission android:name="android.permission.INTERNET" /> in the after <application...> tag. it should be put before any of the <activity> tags....
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.