我必须开发一个 android 应用程序。该应用程序执行从 mysql 数据库中检索数据并显示在 android 模拟器和 android 设备上。
首先,我必须在 localhost 上设置 tomcat 服务器并在 localhost 上运行这些 wsdl 文件,这意味着检索数据已成功显示在模拟器和 android 设备上。
另外我必须在远程设置tomcat服务器。在这里我上传了我的war文件并获取了wsdl文件。现在我必须放置这些wsdl URL意味着在我的模拟器和android设备上都出现黑屏。
我的控制台窗口显示以下错误:
11-19 19:43:26.331: W/System.err(6323): java.lang.ClassCastException: org.ksoap2.serialization.SoapObject
11-19 19:43:26.341: W/System.err(6323): at com.retailer.client.RetailerActivity.onCreate(RetailerActivity.java:36)
11-19 19:43:26.341: W/System.err(6323): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-19 19:43:26.341: W/System.err(6323): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-19 19:43:26.341: W/System.err(6323): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-19 19:43:26.341: W/System.err(6323): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-19 19:43:26.341: W/System.err(6323): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-19 19:43:26.341: W/System.err(6323): at android.os.Handler.dispatchMessage(Handler.java:99)
11-19 19:43:26.341: W/System.err(6323): at android.os.Looper.loop(Looper.java:123)
11-19 19:43:26.341: W/System.err(6323): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-19 19:43:26.341: W/System.err(6323): at java.lang.reflect.Method.invokeNative(Native Method)
11-19 19:43:26.341: W/System.err(6323): at java.lang.reflect.Method.invoke(Method.java:521)
11-19 19:43:26.341: W/System.err(6323): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-19 19:43:26.341: W/System.err(6323): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-19 19:43:26.341: W/System.err(6323): at dalvik.system.NativeStart.main(Native Method)
我该如何解决这个错误。请帮助我。
这是我的代码:
public class RetailerActivity extends Activity {
private static final String SOAP_ACTION = "http://ws.testprops.com/customerData";
private static final String METHOD_NAME = "customerData";
private static final String NAMESPACE = "http://ws.testprops.com";
//private static final String URL = "http://10.0.0.133:8089/TestPrompts/services/Fetch?wsdl";
private static final String URL = "http://87.76.29.180:8080/TestPrompts/services/Fetch?wsdl";
/*
private static final String SOAP_ACTION = "http://xcart.com/customerData";
private static final String METHOD_NAME = "customerData";
private static final String NAMESPACE = "http://xcart.com";
private static final String URL = "http://10.0.0.133:8089/XcartLogin/services/Fetch?wsdl";*/
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
try {
ht.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
SoapPrimitive s = response;
String str = s.toString();
String resultArr[] = str.split("&");//Result string will split & store in an array
TextView tv = new TextView(this);
for(int i = 0; i<resultArr.length;i++){
tv.append(resultArr[i]+"\n\n");
}
setContentView(tv);
} catch (Exception e) {
//Log.e("Error : " , "Error on soapPrimitiveData() " + e.getMessage());
e.printStackTrace();
}
}
}
这是我的第 36 行:
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
我必须把这个网址
private static final String URL = "10.0.0.133:8089/TestPrompts/services/Fetch?wsdl";
意味着正在检索数据。这个 wsdl 文件在 localhost 的 Tomcat 服务器上运行。
但我必须把这些网址的意思
private static final String URL = "87.76.29.180:8080/TestPrompts/services/Fetch?wsdl";
这次只是在错误之上。这个 wsdl 文件在远程的 Tomcat 服务器上运行。