我的fyp演示后的第二天和我的移动帮助给了我这个错误。
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;
表格名称
@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();
模拟器IP
String [] params =new String [] {"10.0.2.2",inputId};
我的电脑IP
//String [] params =new String [] {"192.168.0.106",inputId};
new MyAsyncTask().execute(params);
}
这是我对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();
}
当代码出现在此部分时,它崩溃了应用程序,并且遗憾的是应用已停止
return response.toString();
}
@Override
public void onPostExecute(final String result)
{
super.onPostExecute(result);
mHandler.post(new Runnable()
{
@Override
public void run(){
textView1.setText(result);
}
});
}
}
这是我的网络服务
[WebMethod]
public string empget(int eid)
{
员工详细信息
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;
}