-4

当我运行我的 android 应用程序时,它什么也没有显示,然后它说:不幸的是,WSConnection 已停止。

只显示该消息...我尝试与普通未更改的android应用程序进行比较并尝试了一些东西,但一切都导致了同样的事情...

JAVA代码如下:

package com.androidclient.ws;

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.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;

import com.wsconnection.R;

public class WSClientActivity extends Activity 
    {
        private static final String SOAP_ACTION = "http://192.168.0.25/webapplication1/ws.asmx";
        private static final String METHOD_NAME = "HelloWorld";
        private static final String NAMESPACE = "http://microsoft.com/webservices/";
        private static final String URL = "http://192.168.0.25/webapplication1/ws.asmx?WSDL";
        /** Called when the activity is first created. */

        @Override
        public boolean onCreateOptionsMenu(Menu menu) 
            {
                getMenuInflater().inflate(R.menu.activity_main, menu);
                return true;
            }

        /*
        @Override
        public void onCreate(Bundle savedInstanceState) 
           {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
           }
        */


        public void klicWS()
        {
             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();

                    TextView tv = new TextView(this);
                    tv.setText("Message :"+response.toString());
                    setContentView(tv);

                } 

             catch (Exception e) 
                {
                    e.printStackTrace();
                }
        }

    }


//XML CODE BELOW:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:id="@+id/pager"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     tools:context="com.androidclient.ws.WSClientActivity" >

     <EditText
         android:id="@+id/editText2"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:hint="@string/text2"
         android:inputType="textNoSuggestions"
         android:ems="20" />

     <Button
         android:id="@+id/button1"
         android:layout_width="177dp"
         android:layout_height="86dp"
         android:text="@string/button1" />

</FrameLayout>
4

1 回答 1

4

You must call setContentView(int) in your onCreate(Bundle) method. You cannot just get rid of it.

于 2012-10-19T12:05:20.820 回答