この問題に関する多くの投稿があることを知っています。ただし、Android 3.0 以降でビルドされています (AsyncTask を使用)。私は自分の解決策を見つけることができませんでした。Web サービスからの情報の取得に問題があります。これが私のコードです:
package com.example.marport;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;
public class Ithalatfaturalama extends Activity implements OnClickListener {
EditText KonteynerNo;
DatePicker DatePicker;
Button Sorgula;
TextView TextResult;
List<String> toBeSentList;
Iterator<String> it;
Date toBeSentDate;
SoapObject request;
SoapSerializationEnvelope envelope;
HttpTransportSE aps;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.ithalatfaturalama);
defineVars();
Sorgula.setOnClickListener(this);
}
private void defineVars() {
KonteynerNo = (EditText)findViewById(R.id.etKonteynerBill);
DatePicker = (DatePicker)findViewById(R.id.datePicker1);
Sorgula = (Button)findViewById(R.id.bSorgulaBill);
TextResult = (TextView)findViewById(R.id.tvResultBill);
toBeSentList = new ArrayList<String>();
request = new SoapObject(WSDefinition.NAMESPACE,WSDefinition.REPORTS);
toBeSentDate = new Date();
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
}
@Override
public void onClick(View v) {
String containerInfo = KonteynerNo.getText().toString();
toBeSentList.add(containerInfo);
it = toBeSentList.iterator();
String temp = (String) it.next();
request.addProperty("ids",temp);
int Day = DatePicker.getDayOfMonth();
int Month = DatePicker.getMonth();
int Year = DatePicker.getYear();
toBeSentDate.setYear(Year);
toBeSentDate.setMonth(Month);
toBeSentDate.setDate(Day);
request.addProperty("date",toBeSentDate);
envelope.dotNet = false;
envelope.setOutputSoapObject(request);
try {
aps = new HttpTransportSE(WSDefinition.URL);
aps.call(WSDefinition.REPORTS_ACTION, envelope);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
@SuppressWarnings("unchecked")
Vector<SoapObject> result = (Vector<SoapObject>) envelope.getResponse();
Vector<MarportAgentReport> responseList = new Vector<MarportAgentReport>();
for (SoapObject obj : result) {
MarportAgentReport tmp = new MarportAgentReport(obj);
responseList.add(tmp);
}
String resultStr = "";
for (int i = 0 ; i < responseList.size();i++){
MarportAgentReport tmp = responseList.get(i);
resultStr += (i+1) +".Category = "+tmp.getCategory()+"\n";
resultStr += (i+1) +".Container = "+tmp.getContainer()+"\n";
resultStr += (i+1) +".InShip= "+tmp.getInShip()+"\n";
resultStr += (i+1) +".IsoCode = "+tmp.getIsoCode()+"\n";
resultStr += (i+1) +".Line = "+tmp.getLine()+"\n";
resultStr += (i+1) +".Muhur = "+tmp.getMuhur()+"\n";
resultStr += (i+1) +".OutShip = "+tmp.getOutShip()+"\n";
resultStr += (i+1) +".Position = "+tmp.getPosition()+"\n";
resultStr += (i+1) +".Service = "+tmp.getService()+"\n";
resultStr += (i+1) +".Status = "+tmp.getStatus()+"\n";
resultStr += (i+1) +".Terminal = "+tmp.getTerminal()+"\n";
}
TextResult.setText(resultStr);
} catch (SoapFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
そして、ここに私の目的があります:
package com.example.marport;
import java.io.Serializable;
import java.util.Date;
import java.util.Hashtable;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
/**
* The persistent class for the CONTENT database table.
*
*/
public class MarportAgentReport implements KvmSerializable {
private static final long serialVersionUID = 1L;
private String container;
private String isoCode;
private String category;
private String status;
private String line;
private String service;
private Date serviceDate;
private String terminal;
private String inShip;
private String outShip;
private String muhur;
private String position;
public MarportAgentReport() {
}
public MarportAgentReport(SoapObject obj)
{
obj.getPropertyCount();
obj.getProperty(0);
this.setCategory(obj);
this.setInShip(obj);
this.setContainer(obj);
this.setIsoCode(obj);
this.setLine(obj);
this.setMuhur(obj);
this.setOutShip(obj);
this.setPosition(obj);
this.setService(obj);
this.setStatus(obj);
this.setTerminal(obj);
}
public String getContainer() {
return container;
}
public void setContainer(SoapObject obj) {
try {
this.container = obj.getPropertyAsString("container");
} catch (Exception e) {
this.container = "";
}
}
public String getIsoCode() {
return isoCode;
}
public void setIsoCode(SoapObject obj) {
try {
this.isoCode = obj.getPropertyAsString("isoCode");
} catch (Exception e) {
this.isoCode = "";
}
}
public String getCategory() {
return category;
}
public void setCategory(SoapObject obj) {
try {
this.category = obj.getPropertyAsString("category");
} catch (Exception e) {
this.category = "";
}
}
public String getStatus() {
return status;
}
public void setStatus(SoapObject obj) {
try {
this.status = obj.getPropertyAsString("status");
} catch (Exception e) {
this.status = "";
}
}
public String getLine() {
return line;
}
public void setLine(SoapObject obj) {
try {
this.line = obj.getPropertyAsString("line");
} catch (Exception e) {
this.line = "";
}
}
public String getService() {
return service;
}
public void setService(SoapObject obj) {
try {
this.service = obj.getPropertyAsString("service");
} catch (Exception e) {
this.service = "";
}
}
public Date getServiceDate() {
return serviceDate;
}
public void setServiceDate(Date serviceDate) {
this.serviceDate = serviceDate;
}
public String getTerminal() {
return terminal;
}
public void setTerminal(SoapObject obj) {
try {
this.terminal = obj.getPropertyAsString("terminal");
} catch (Exception e) {
this.terminal = "";
}
}
public String getInShip() {
return inShip;
}
public void setInShip(SoapObject obj) {
try {
this.inShip = obj.getPropertyAsString("inShip");
} catch (Exception e) {
this.inShip = "";
}
}
public String getOutShip() {
return outShip;
}
public void setOutShip(SoapObject obj) {
try {
this.outShip = obj.getPropertyAsString("outShip");
} catch (Exception e) {
this.outShip = "";
}
}
public String getMuhur() {
return muhur;
}
public void setMuhur(SoapObject obj) {
try {
this.muhur = obj.getPropertyAsString("muhur");
} catch (Exception e) {
this.muhur = "";
}
}
public String getPosition() {
return position;
}
public void setPosition(SoapObject obj) {
try {
this.position = obj.getPropertyAsString("position");
} catch (Exception e) {
this.position = "";
}
}
@Override
public Object getProperty(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public int getPropertyCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
// TODO Auto-generated method stub
}
@Override
public void setProperty(int arg0, Object arg1) {
// TODO Auto-generated method stub
}
}
そしてログ:
09-13 07:13:30.484: E/AndroidRuntime(251): FATAL EXCEPTION: main
09-13 07:13:30.484: E/AndroidRuntime(251): java.lang.RuntimeException: Cannot serialize: Fri Sep 13 07:12:31 GMT+00:00 3912
09-13 07:13:30.484: E/AndroidRuntime(251): at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:687)
09-13 07:13:30.484: E/AndroidRuntime(251): at org.ksoap2.serialization.SoapSerializationEnvelope.writeProperty(SoapSerializationEnvelope.java:671)
09-13 07:13:30.484: E/AndroidRuntime(251): at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:640)
09-13 07:13:30.484: E/AndroidRuntime(251): at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:624)
09-13 07:13:30.484: E/AndroidRuntime(251): at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:681)
09-13 07:13:30.484: E/AndroidRuntime(251): at org.ksoap2.serialization.SoapSerializationEnvelope.writeBody(SoapSerializationEnvelope.java:597)
09-13 07:13:30.484: E/AndroidRuntime(251): at org.ksoap2.SoapEnvelope.write(SoapEnvelope.java:192)
09-13 07:13:30.484: E/AndroidRuntime(251): at org.ksoap2.transport.Transport.createRequestData(Transport.java:107)
09-13 07:13:30.484: E/AndroidRuntime(251): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:119)
09-13 07:13:30.484: E/AndroidRuntime(251): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
09-13 07:13:30.484: E/AndroidRuntime(251): at com.example.marport.Ithalatfaturalama.onClick(Ithalatfaturalama.java:81)
09-13 07:13:30.484: E/AndroidRuntime(251): at android.view.View.performClick(View.java:2408)
09-13 07:13:30.484: E/AndroidRuntime(251): at android.view.View$PerformClick.run(View.java:8816)
09-13 07:13:30.484: E/AndroidRuntime(251): at android.os.Handler.handleCallback(Handler.java:587)
09-13 07:13:30.484: E/AndroidRuntime(251): at android.os.Handler.dispatchMessage(Handler.java:92)
09-13 07:13:30.484: E/AndroidRuntime(251): at android.os.Looper.loop(Looper.java:123)
09-13 07:13:30.484: E/AndroidRuntime(251): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-13 07:13:30.484: E/AndroidRuntime(251): at java.lang.reflect.Method.invokeNative(Native Method)
09-13 07:13:30.484: E/AndroidRuntime(251): at java.lang.reflect.Method.invoke(Method.java:521)
09-13 07:13:30.484: E/AndroidRuntime(251): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-13 07:13:30.484: E/AndroidRuntime(251): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-13 07:13:30.484: E/AndroidRuntime(251): at dalvik.system.NativeStart.main(Native Method)
ありがとうございました。