0

The day after my fyp presentation and my mobile help give me this error.

package com.example.nauma.myapplication;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
 import org.ksoap2.*;
 import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
public class MainActivity extends Activity {

private EditText editText1;
private TextView textView1;
private Handler mHandler=new Handler();
private String inputId;

Form name

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    editText1=(EditText) findViewById(R.id.editText1);
    textView1=(TextView)findViewById(R.id.textView1);


}

public void getMaterial (View v)
{
    String inputId=editText1.getText().toString();

emulator IP

    String [] params =new String [] {"10.0.2.2",inputId};

my pc IP

    //String [] params =new String [] {"192.168.0.106",inputId};

    new MyAsyncTask().execute(params);

}

This is my operation of webservices

class MyAsyncTask extends AsyncTask <String, Void, String>
{
    public String SOAP_ACTION= "http://threepin.org/empget";
    public String OPERATION_NAME ="empget";
    public String WSDL_TARGET_NAMESPACE="http://threepin.org/";
    public String SOAP_ADDRESS;
    private SoapObject request;
    private HttpTransportSE httpTransport;
    private SoapSerializationEnvelope envelope;
    Object response=null;



    @Override
    protected String doInBackground(String... params)
    {

        SOAP_ADDRESS ="http://"+params[0]+"/WebService1.asmx";
        request=new SoapObject (WSDL_TARGET_NAMESPACE,OPERATION_NAME);
        PropertyInfo pi=new PropertyInfo();
        pi.setName("id");
        pi.setValue(Integer.parseInt(params[1]));
        pi.setType(Integer.class);
        request.addProperty(pi);
        pi=new PropertyInfo();

        envelope =new SoapSerializationEnvelope (SoapEnvelope.VER11);
        envelope.dotNet=true;
        envelope.setOutputSoapObject(request);
        httpTransport=new HttpTransportSE (SOAP_ADDRESS);
        try
        {
            httpTransport.call(SOAP_ACTION, envelope);
            response=envelope.getResponse();
        }
        catch (Exception exp){
            response=exp.getMessage();
        }

When code come on this section it crash application and give error unfortunately the app has stopped

        return response.toString();
    }
    @Override
    public void onPostExecute(final String result)
    {
        super.onPostExecute(result);
        mHandler.post(new Runnable()
        {
            @Override
            public void run(){
                textView1.setText(result);
            }
        });
    }
}

This is my Web Service

   [WebMethod]
    public string empget(int eid)
    {

Employee detail

        conn.con.Open();
        string sqlcommand = "select emp_first_name,salary,position from
         tbl_employee_tbl where employee_id='" + eid + "'";
        SqlCommand cmd = new SqlCommand(sqlcommand, conn.con);

        SqlDataReader reader = cmd.ExecuteReader();
        string abc = null;
        while (reader.Read())
        {
            string Ename = reader["emp_first_name"].ToString();
            string Esalary = reader["salary"].ToString();
            string Eposition = reader["position"].ToString();

            abc = "emp_first_name=" + Ename + "," + "salary=" + Esalary +
           "," + "position=" + Eposition;
        }
        conn.con.Close();
        return abc;


    }
halfer
  • 19,824
  • 17
  • 99
  • 186
  • 5
    Use LogCat to examine the Java stack trace associated with your crash: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare Nov 30 '16 at 23:43
  • 1
    It may not be clear that your piece of code is one block, and your explanatory notes have been inserted in. You may find turning some of these into `// Comments` proper makes it a bit clearer. I removed them from the code as your notes would presently stop a helpful reader wanting to compile your code. – halfer Dec 01 '16 at 08:32

0 Answers0