Java 以值数组的形式从SOAP web服务获取数据
我在android studio中有一个项目,我的数据库来自一个web服务 我使用下面的代码在表中显示数据。但它给了我这个错误 不幸的是,应用程序已经停止 有人能帮我解决这个问题吗 我的代码: Student.javaJava 以值数组的形式从SOAP web服务获取数据,java,android,web-services,soap,Java,Android,Web Services,Soap,我在android studio中有一个项目,我的数据库来自一个web服务 我使用下面的代码在表中显示数据。但它给了我这个错误 不幸的是,应用程序已经停止 有人能帮我解决这个问题吗 我的代码: Student.java package com....; import org.ksoap2.serialization.KvmSerializable; import org.ksoap2.serialization.PropertyInfo; import java.util.Hashtable
package com....;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
import java.util.Hashtable;
/**
* Created by SA on 4/27/2015.
*/
class Student implements KvmSerializable
{
String Course_ID;
String Section;
String Time;
//String Days;
public Student()
{}
public Student(String Course_ID,String Section,String Time){
this.Course_ID=Course_ID;
this.Section=Section;
this.Time=Time;
// this.Days=Days;
}
public Object getProperty(int arg0) {
switch(arg0)
{
case 0:
return Course_ID;
case 1:
return Section;
case 2:
return Time;
}
return null;
}
public int getPropertyCount() {
return 3;
}
@SuppressWarnings("rawtypes")
public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
switch(index)
{
case 0:
info.type = PropertyInfo.STRING_CLASS;
info.name= "Course_ID";
break;
case 1:
info.type = PropertyInfo.STRING_CLASS;
info.name = "Section";
break;
case 2:
info.type = PropertyInfo.STRING_CLASS;
info.name = "Time";
break;
default:
break;
}
}
public void setProperty(int index, Object value) {
switch(index)
{
case 0:
Course_ID = value.toString();
break;
case 1:
Section = value.toString();
break;
case 2:
Time = value.toString();
break;
default:
break;
}
}
}
package com....;
import java.io.IOException;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.ArrayList;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import java.util.Arrays;
import java.util.Hashtable;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.TableRow.LayoutParams;
public class LOGIN extends Activity
{
EditText editText= (EditText) findViewById(R.id.editText);
boolean timeoutexcep=false,httpexcep=false,generalexcep=false;
Student [] personList2;
TableLayout tl1;
String[] Course_ID,Section,Time,Days;
int i;
String SID="201001810";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
new propdetail().execute();
}
class propdetail extends AsyncTask<Void, Void, Void> {
private final ProgressDialog dialog = new ProgressDialog(LOGIN.this);
@Override
protected void onPreExecute() {
this.dialog.setMessage("Loading data");
this.dialog.show();
}
@Override
protected Void doInBackground(Void... unused) {
final String NAMESPACE = "http://tempuri.org/";
final String URL = "http://192.168.1.101/SAWSANS/connect.asmx";
final String SOAP_ACTION = "http://tempuri.org/GetECources";
final String METHOD_NAME = "GetECources";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("SID",SID);
Student C = new Student();
PropertyInfo pi = new PropertyInfo();
pi.setName("Student");
pi.setValue(C);
pi.setType(C.getClass());
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
envelope.addMapping(NAMESPACE, "Student", new Student().getClass());
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject) envelope.getResponse();
Log.i("SelfAdvising", request.toString());
System.out.println("check dddddddddddddd" + response);
envelope.addMapping(NAMESPACE,"Student",new Student().getClass());
androidHttpTransport.call(SOAP_ACTION, envelope);
personList2 = new Student[response.getPropertyCount()];
for (int j = 0; j < personList2.length; j++) {
SoapObject so = (SoapObject) response.getProperty(j);
Student person2 = new Student();
person2.Course_ID = so.getProperty(0).toString();
person2.Section= so.getPropertyAsString(1).toString();
person2.Time=so.getPropertyAsString(6).toString();
// person2.Days=so.getPropertyAsString(7).toString();
personList2[j] = person2;
}
Course_ID= new String[personList2.length];
Section = new String[personList2.length];
Time = new String[personList2.length];
//Days = new String[personList2.length];
for (int i = 0; i < personList2.length; i++)
{
Section[i] = Arrays.asList(personList2[i].Section).toString();
Time[i] = Arrays.asList(personList2[i].Time).toString();
Course_ID[i] = Arrays.asList(personList2[i].Course_ID).toString();
// Days[i] = Arrays.asList(personList2[i].Days).toString();
System.out.println(Course_ID[i]);
System.out.println(Section[i]);
System.out.println(Time[i]);
// System.out.println(Days[i]);
}
}
catch(SocketTimeoutException e){
timeoutexcep=true;
e.printStackTrace();
}
catch(ConnectException e){
httpexcep=true;
e.printStackTrace();
}
catch (Exception e) {
generalexcep=true;
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}
if(timeoutexcep){
Toast.makeText(LOGIN.this, "Unable to connect to server, Please try again later",Toast.LENGTH_LONG).show();
}
else if(httpexcep){
Toast.makeText(LOGIN.this, "Please check your Internet connection",Toast.LENGTH_LONG).show();
}
else if(generalexcep){
Toast.makeText(LOGIN.this, "Please try later",Toast.LENGTH_LONG).show();
}
else {
tableview();
}
timeoutexcep=false;httpexcep=false;generalexcep=false;
}
}
public void tableview(){
tl1 = (TableLayout) findViewById(R.id.tl);
for (i = 0; i < personList2.length; i++)
{
final TableRow tr = new TableRow(this);
LayoutParams lp = new LayoutParams(150,LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
tr.setId(i);
tr.setLayoutParams(lp);
lp.setMargins(0, 20, 0,0);
final TextView tvLeft = new TextView(this);
tvLeft.setLayoutParams(lp);
tvLeft.setText(Course_ID[i]);
final TextView tvCenter = new TextView(this);
tvCenter.setLayoutParams(lp);
tvCenter.setText(Section[i]);
final TextView tvRight = new TextView(this);
tvRight.setLayoutParams(lp);
tvRight.setText(Time[i]);
//final TextView tvend = new TextView(this);
//tvend.setLayoutParams(lp);
//tvend.setText(Days[i]);
tr.addView(tvLeft);
tr.addView(tvCenter);
tr.addView(tvRight);
//tr.addView(tvend);
tl1.addView(tr, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_login, menu);
return true;
}
}
LOGIN.java
package com....;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
import java.util.Hashtable;
/**
* Created by SA on 4/27/2015.
*/
class Student implements KvmSerializable
{
String Course_ID;
String Section;
String Time;
//String Days;
public Student()
{}
public Student(String Course_ID,String Section,String Time){
this.Course_ID=Course_ID;
this.Section=Section;
this.Time=Time;
// this.Days=Days;
}
public Object getProperty(int arg0) {
switch(arg0)
{
case 0:
return Course_ID;
case 1:
return Section;
case 2:
return Time;
}
return null;
}
public int getPropertyCount() {
return 3;
}
@SuppressWarnings("rawtypes")
public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
switch(index)
{
case 0:
info.type = PropertyInfo.STRING_CLASS;
info.name= "Course_ID";
break;
case 1:
info.type = PropertyInfo.STRING_CLASS;
info.name = "Section";
break;
case 2:
info.type = PropertyInfo.STRING_CLASS;
info.name = "Time";
break;
default:
break;
}
}
public void setProperty(int index, Object value) {
switch(index)
{
case 0:
Course_ID = value.toString();
break;
case 1:
Section = value.toString();
break;
case 2:
Time = value.toString();
break;
default:
break;
}
}
}
package com....;
import java.io.IOException;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.ArrayList;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import java.util.Arrays;
import java.util.Hashtable;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.TableRow.LayoutParams;
public class LOGIN extends Activity
{
EditText editText= (EditText) findViewById(R.id.editText);
boolean timeoutexcep=false,httpexcep=false,generalexcep=false;
Student [] personList2;
TableLayout tl1;
String[] Course_ID,Section,Time,Days;
int i;
String SID="201001810";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
new propdetail().execute();
}
class propdetail extends AsyncTask<Void, Void, Void> {
private final ProgressDialog dialog = new ProgressDialog(LOGIN.this);
@Override
protected void onPreExecute() {
this.dialog.setMessage("Loading data");
this.dialog.show();
}
@Override
protected Void doInBackground(Void... unused) {
final String NAMESPACE = "http://tempuri.org/";
final String URL = "http://192.168.1.101/SAWSANS/connect.asmx";
final String SOAP_ACTION = "http://tempuri.org/GetECources";
final String METHOD_NAME = "GetECources";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("SID",SID);
Student C = new Student();
PropertyInfo pi = new PropertyInfo();
pi.setName("Student");
pi.setValue(C);
pi.setType(C.getClass());
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
envelope.addMapping(NAMESPACE, "Student", new Student().getClass());
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject) envelope.getResponse();
Log.i("SelfAdvising", request.toString());
System.out.println("check dddddddddddddd" + response);
envelope.addMapping(NAMESPACE,"Student",new Student().getClass());
androidHttpTransport.call(SOAP_ACTION, envelope);
personList2 = new Student[response.getPropertyCount()];
for (int j = 0; j < personList2.length; j++) {
SoapObject so = (SoapObject) response.getProperty(j);
Student person2 = new Student();
person2.Course_ID = so.getProperty(0).toString();
person2.Section= so.getPropertyAsString(1).toString();
person2.Time=so.getPropertyAsString(6).toString();
// person2.Days=so.getPropertyAsString(7).toString();
personList2[j] = person2;
}
Course_ID= new String[personList2.length];
Section = new String[personList2.length];
Time = new String[personList2.length];
//Days = new String[personList2.length];
for (int i = 0; i < personList2.length; i++)
{
Section[i] = Arrays.asList(personList2[i].Section).toString();
Time[i] = Arrays.asList(personList2[i].Time).toString();
Course_ID[i] = Arrays.asList(personList2[i].Course_ID).toString();
// Days[i] = Arrays.asList(personList2[i].Days).toString();
System.out.println(Course_ID[i]);
System.out.println(Section[i]);
System.out.println(Time[i]);
// System.out.println(Days[i]);
}
}
catch(SocketTimeoutException e){
timeoutexcep=true;
e.printStackTrace();
}
catch(ConnectException e){
httpexcep=true;
e.printStackTrace();
}
catch (Exception e) {
generalexcep=true;
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}
if(timeoutexcep){
Toast.makeText(LOGIN.this, "Unable to connect to server, Please try again later",Toast.LENGTH_LONG).show();
}
else if(httpexcep){
Toast.makeText(LOGIN.this, "Please check your Internet connection",Toast.LENGTH_LONG).show();
}
else if(generalexcep){
Toast.makeText(LOGIN.this, "Please try later",Toast.LENGTH_LONG).show();
}
else {
tableview();
}
timeoutexcep=false;httpexcep=false;generalexcep=false;
}
}
public void tableview(){
tl1 = (TableLayout) findViewById(R.id.tl);
for (i = 0; i < personList2.length; i++)
{
final TableRow tr = new TableRow(this);
LayoutParams lp = new LayoutParams(150,LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
tr.setId(i);
tr.setLayoutParams(lp);
lp.setMargins(0, 20, 0,0);
final TextView tvLeft = new TextView(this);
tvLeft.setLayoutParams(lp);
tvLeft.setText(Course_ID[i]);
final TextView tvCenter = new TextView(this);
tvCenter.setLayoutParams(lp);
tvCenter.setText(Section[i]);
final TextView tvRight = new TextView(this);
tvRight.setLayoutParams(lp);
tvRight.setText(Time[i]);
//final TextView tvend = new TextView(this);
//tvend.setLayoutParams(lp);
//tvend.setText(Days[i]);
tr.addView(tvLeft);
tr.addView(tvCenter);
tr.addView(tvRight);
//tr.addView(tvend);
tl1.addView(tr, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_login, menu);
return true;
}
}
package com。。。。;
导入java.io.IOException;
导入java.net.ConnectException;
导入java.net.SocketTimeoutException;
导入java.util.ArrayList;
导入java.util.ArrayList;
导入org.ksoap2.SoapEnvelope;
导入org.ksoap2.serialization.PropertyInfo;
导入org.ksoap2.serialization.SoapObject;
导入org.ksoap2.serialization.SoapPrimitive;
导入org.ksoap2.serialization.SoapSerializationEnvelope;
导入org.ksoap2.transport.HttpTransportSE;
导入java.util.array;
导入java.util.Hashtable;
导入org.ksoap2.serialization.KvmSerializable;
导入org.ksoap2.serialization.PropertyInfo;
导入android.app.Activity;
导入android.app.ProgressDialog;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.Menu;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.widget.AdapterView;
导入android.widget.AdapterView.OnItemClickListener;
导入android.widget.ArrayAdapter;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.ListView;
导入android.widget.TableLayout;
导入android.widget.TableRow;
导入android.widget.TextView;
导入android.widget.Toast;
导入android.widget.TableRow.LayoutParams;
公共类登录扩展活动
{
EditText EditText=(EditText)findViewById(R.id.EditText);
布尔timeoutexcep=false,httpexcep=false,generalexcep=false;
学生[]个人2;
表tl1;
字符串[]课程ID、区段、时间、天数;
int i;
字符串SID=“201001810”;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u登录);
新建propdetail().execute();
}
类propdetail扩展了异步任务{
private final ProgressDialog=新建ProgressDialog(LOGIN.this);
@凌驾
受保护的void onPreExecute(){
this.dialog.setMessage(“加载数据”);
this.dialog.show();
}
@凌驾
受保护的空位背景(空位…未使用){
最终字符串名称空间=”http://tempuri.org/";
最终字符串URL=”http://192.168.1.101/SAWSANS/connect.asmx";
最后一个字符串SOAP_ACTION=”http://tempuri.org/GetECources";
最终字符串方法\u NAME=“GetECources”;
SoapObject请求=新的SoapObject(名称空间、方法名称);
addProperty(“SID”,SID);
学生C=新学生();
PropertyInfo pi=新的PropertyInfo();
pi.设置名称(“学生”);
pi.设定值(C);
setType(C.getClass());
请求。添加属性(pi);
SoapSerializationEnvelope=新的SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(请求);
addMapping(名称空间“Student”,newstudent().getClass());
HttpTransportSE androidHttpTransport=新的HttpTransportSE(URL);
androidHttpTransport.debug=true;
试一试{
调用(SOAP_操作,信封);
SoapObject响应=(SoapObject)信封.getResponse();
Log.i(“自我建议”,request.toString());
System.out.println(“检查DDDD”+响应);
addMapping(名称空间“Student”,newstudent().getClass());
调用(SOAP_操作,信封);
personList2=新学生[response.getPropertyCount()];
对于(int j=0;j