今、私はAndroidEclipseからWebサービスを利用するためにSOAPメソッドを使用しました。
edittextから入力を取得し、適切な値を表示する必要があります。つまり、Webサービスを呼び出して結果を返す必要があります。
エミュレータが実行されると、「ERROR:java.lang.RuntimeException:Cannotserialize0004」と表示されます。このエラーを解決するにはどうすればよいですか。
これが私のコードです、見つけてください
screen.java
public class X_classActivity extends Activity
{
private EditText edit;
private Button btn;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edit = (EditText) findViewById(R.id.editText1);
btn = (Button)findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
fun();
}
});
}
private void fun()
{
//getSOAPResponse() method returns SOAP Response
SoapObject soapResponseObject = getSOAPResponse(edit.getText());
}
public SoapObject getSOAPResponse(GetChars search)
{
SoapObject soapObject = new SoapObject("http://tempuri.org/", "GetName");
soapObject.addProperty("str", search);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.dotNet = true;
envelope.setOutputSoapObject(soapObject);
HttpTransportSE androidHttpTransport = new HttpTransportSE("http://122.248.240.105:234/Service1.asmx?WSDL");
try
{
androidHttpTransport.call("http://tempuri.org/GetName", envelope);//call the eb service Method
Object result = envelope.getResponse();
System.out.println(" " + result.toString());
((TextView) findViewById (R.id.textView2)).setText(""+result.toString());
}
catch (Exception E)
{
E.printStackTrace();
((TextView) findViewById (R.id.textView2)).setText("ERROR:" + E.getClass().getName() + ":" + E.getMessage());
}
return soapObject;
}
}
Logcat
06-01 18:39:56.020: W/KeyCharacterMap(932): No keyboard for id 0
06-01 18:39:56.020: W/KeyCharacterMap(932): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
06-01 18:40:00.510: W/System.err(932): java.lang.RuntimeException: Cannot serialize: 0004
06-01 18:40:00.520: W/System.err(932): at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:661)
06-01 18:40:00.520: W/System.err(932): at org.ksoap2.serialization.SoapSerializationEnvelope.writeProperty(SoapSerializationEnvelope.java:645)
06-01 18:40:00.520: W/System.err(932): at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:614)
06-01 18:40:00.520: W/System.err(932): at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:598)
06-01 18:40:00.520: W/System.err(932): at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:655)
06-01 18:40:00.530: W/System.err(932): at org.ksoap2.serialization.SoapSerializationEnvelope.writeBody(SoapSerializationEnvelope.java:579)
06-01 18:40:00.530: W/System.err(932): at org.ksoap2.SoapEnvelope.write(SoapEnvelope.java:192)
06-01 18:40:00.530: W/System.err(932): at org.ksoap2.transport.Transport.createRequestData(Transport.java:74)
06-01 18:40:00.530: W/System.err(932): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:58)
06-01 18:40:00.530: W/System.err(932): at com.x.x.x.X_classActivity.getSOAPResponse(X_classActivity.java:57)
06-01 18:40:00.530: W/System.err(932): at com.x.x.x.X_classActivity.fun(X_classActivity.java:45)
06-01 18:40:00.530: W/System.err(932): at com.x.x.x.X_classActivity.access$0(X_classActivity.java:41)
06-01 18:40:00.530: W/System.err(932): at com.x.x.x.X_classActivity$1.onClick(X_classActivity.java:36)
06-01 18:40:00.530: W/System.err(932): at android.view.View.performClick(View.java:2408)
06-01 18:40:00.530: W/System.err(932): at android.view.View$PerformClick.run(View.java:8816)
06-01 18:40:00.530: W/System.err(932): at android.os.Handler.handleCallback(Handler.java:587)
06-01 18:40:00.530: W/System.err(932): at android.os.Handler.dispatchMessage(Handler.java:92)
06-01 18:40:00.530: W/System.err(932): at android.os.Looper.loop(Looper.java:123)
06-01 18:40:00.530: W/System.err(932): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-01 18:40:00.530: W/System.err(932): at java.lang.reflect.Method.invokeNative(Native Method)
06-01 18:40:00.530: W/System.err(932): at java.lang.reflect.Method.invoke(Method.java:521)
06-01 18:40:00.540: W/System.err(932): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-01 18:40:00.540: W/System.err(932): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-01 18:40:00.540: W/System.err(932): at dalvik.system.NativeStart.main(Native Method)
ウェブメソッド
public class GetName {
public String GetName(String str){
return(str);
} }
どうもありがとう!!..