关于调用从Android上的web服务,这是returnig错误的一个示例应用程序,"不幸的是,MyTest的停止和QUOT ;. [英] An sample application on calling the webservices from android, which is returnig the error, "Unfortunately,MyTest has stopped".
问题描述
我有一个code,这使得通过WWW,tempuri.org所提供的Web服务的调用。
当我试图运行应用程序,应用程序意外停止,并显示信息 - 不幸的是,MyTest的已经停止。这里是我的java文件 -
I have a code, which makes a call to the web service provided by www,tempuri.org. While I am trying to run the application, the application is stopping unexpectedly and showing the message - "Unfortunately, MyTest has stopped".. Here is my java file -
MainActivity.java: -
MainActivity.java :-
package com.example.mytest;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
public static final String SOAP_ACTION = "http://tempuri.org/CelciusToFarenheit";
public static final String METHOD_NAME = "CelciusToFarenheit";
public static final String NAMESPACE= "http://tempuri.org/";
public static final String URL = "http://www.w3schools.com/webservices/tempconvert.asmx";
TextView tv;
SoapEnvelope se;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv= (TextView) findViewById(R.id.TextView01);
SoapObject Request=new SoapObject(NAMESPACE,METHOD_NAME);
Request.addProperty("Celcius","32");
SoapSerializationEnvelope sse = new SoapSerializationEnvelope (se.VER11);
sse.dotNet=true;
sse.setOutputSoapObject(Request);
HttpTransportSE abt = new HttpTransportSE(URL);
try
{
abt.call(SOAP_ACTION,se);
SoapObject resultString=(SoapObject)sse.getResponse();
String resultData=resultString.getProperty(0).toString();
tv.setText("Status :"+resultString);
}
catch(Exception e)
{
e.printStackTrace();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
activity_main.xml中: -
activity_main.xml :-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
的logcat的如下 -
The logcat is as follows -
08-10 01:35:10.421: E/AndroidRuntime(1077): FATAL EXCEPTION: main
08-10 01:35:10.421: E/AndroidRuntime(1077): java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
08-10 01:35:10.421: E/AndroidRuntime(1077): at com.example.mytest.MainActivity.onCreate(MainActivity.java:30)
08-10 01:35:10.421: E/AndroidRuntime(1077): at android.app.Activity.performCreate(Activity.java:5133)
08-10 01:35:10.421: E/AndroidRuntime(1077): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-10 01:35:10.421: E/AndroidRuntime(1077): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-10 01:35:10.421: E/AndroidRuntime(1077): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-10 01:35:10.421: E/AndroidRuntime(1077): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-10 01:35:10.421: E/AndroidRuntime(1077): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-10 01:35:10.421: E/AndroidRuntime(1077): at android.os.Handler.dispatchMessage(Handler.java:99)
08-10 01:35:10.421: E/AndroidRuntime(1077): at android.os.Looper.loop(Looper.java:137)
08-10 01:35:10.421: E/AndroidRuntime(1077): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-10 01:35:10.421: E/AndroidRuntime(1077): at java.lang.reflect.Method.invokeNative(Native Method)
08-10 01:35:10.421: E/AndroidRuntime(1077): at java.lang.reflect.Method.invoke(Method.java:525)
08-10 01:35:10.421: E/AndroidRuntime(1077): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-10 01:35:10.421: E/AndroidRuntime(1077): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-10 01:35:10.421: E/AndroidRuntime(1077): at dalvik.system.NativeStart.main(Native Method)
我是新与Android开发Web服务。能否请你建议我,有什么该怎么做?
I am new to develop web services with android. Can you please suggest me, what to do with this?
推荐答案
尼尔默尔的回答上面的伎俩我。但是,我不得不更新行动,命名如下:
Nirmal's answer above did the trick for me. However, I had to update action and namespace as follows:
private static final String SOAP_ACTION = "http://www.w3schools.com/webservices/CelsiusToFahrenheit";
private static final String NAMESPACE = "http://www.w3schools.com/webservices/";
我想通了正确的价值观应该是什么:
I figured out what the correct values should be by:
点击服务原文链接: http://www.w3schools.com /webservices/tempconvert.asmx?WSDL
搜索字符串(不区分大小写)行动,并在该XML命名,然后使用值它们有
Searching for the strings (case-insensitive) "action" and "namespace" in that xml, and then use the values they have
这篇关于关于调用从Android上的web服务,这是returnig错误的一个示例应用程序,&QUOT;不幸的是,MyTest的停止和QUOT ;.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!