私はアンドロイドで石鹸の解析を行っています。これらは、解析中に実行する次の手順です 1) ksoap2-android-assembly-2.4-jar-with-dependencies (1).jar をダウンロードしています。2) 次に、このコードでこれを使用しましたが、このエラーが発生しています。
**java.lang.ClassCastException: org.ksoap2.serialization.SoapPrimitive cannot be cast to org.ksoap2.serialization.SoapObject**
これが私のコードです。
package com.example.networkconnectivity;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
public class MainActivity extends Activity {
private static final String SOAP_ACTION = "http://wsendpoints.bbrailapps.firstgroup.com/getVersion";
private static final String METHOD_NAME = "getVersion";
private static final String NAMESPACE = "http://wsendpoints.bbrailapps.firstgroup.com";
private static final String URL = "http://railapps.firstgroup.com/FirstGroupRailApps/services/RailAppsCAWS?wsdl";
private SoapObject resultRequestSOAP = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
System.out.println("=====================" + haveNetworkConnection());
new AsyncTask<Void, Void, String>() {
ProgressDialog dialog = new ProgressDialog(MainActivity.this);
protected void onPreExecute() {
dialog.show();
};
protected String doInBackground(Void[] params) {
resultRequestSOAP = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envp = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envp.dotNet = true;
envp.setOutputSoapObject(resultRequestSOAP);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(
URL);
try {
androidHttpTransport.call(SOAP_ACTION, envp);
SoapPrimitive resultsString = (SoapPrimitive)envp.getResponse();
return resultRequestSOAP.toString();
} catch (Exception e) {
Log.i("WS Error->", e.toString());
return e.toString();
}
};
protected void onPostExecute(String result) {
dialog.dismiss();
Toast.makeText(MainActivity.this,
"Check Network connectivety" + result,
Toast.LENGTH_LONG).show();
};
}.execute();
}
public boolean haveNetworkConnection() {
boolean haveConnectedWifi = false;
boolean haveConnectedMobile = false;
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] netInfo = cm.getAllNetworkInfo();
for (NetworkInfo ni : netInfo) {
if (ni.getTypeName().equalsIgnoreCase("WIFI"))
if (ni.isConnected())
haveConnectedWifi = true;
if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
if (ni.isConnected())
haveConnectedMobile = true;
}
return haveConnectedWifi || haveConnectedMobile;
}
}