无法启动android app.Logcat错误

时间:2012-08-30 10:10:02

标签: android web-services

我试图通过SOAP方法在android中使用Web服务,但我在logcat上获取这些东西。任何人都可以告诉我这个logcat要求我的东西。

模拟器就是这样显示的 抱歉,您的应用意外停止。强制关闭

谢谢你的时间!。

logcat的

08-30 15:34:50.849: D/AndroidRuntime(409): Shutting down VM
08-30 15:34:50.849: W/dalvikvm(409): threadid=1: thread exiting with uncaught     exception (group=0x4001d800)
08-30 15:34:50.879: E/AndroidRuntime(409): FATAL EXCEPTION: main
08-30 15:34:50.879: E/AndroidRuntime(409): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.soap_frontend/com.example.soap_frontend.MainActivity}: java.lang.NullPointerException
08-30 15:34:50.879: E/AndroidRuntime(409):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-30 15:34:50.879: E/AndroidRuntime(409):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-30 15:34:50.879: E/AndroidRuntime(409):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-30 15:34:50.879: E/AndroidRuntime(409):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-30 15:34:50.879: E/AndroidRuntime(409):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-30 15:34:50.879: E/AndroidRuntime(409):  at android.os.Looper.loop(Looper.java:123)
08-30 15:34:50.879: E/AndroidRuntime(409):  at  android.app.ActivityThread.main(ActivityThread.java: 4627)
08-30 15:34:50.879: E/AndroidRuntime(409):  at java.lang.reflect.Method.invokeNative(Native Method)
08-30 15:34:50.879: E/AndroidRuntime(409):  at java.lang.reflect.Method.invoke(Method.java:521)
08-30 15:34:50.879: E/AndroidRuntime(409):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-30 15:34:50.879: E/AndroidRuntime(409):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-30 15:34:50.879: E/AndroidRuntime(409):  at dalvik.system.NativeStart.main(Native Method)
08-30 15:34:50.879: E/AndroidRuntime(409): Caused by: java.lang.NullPointerException
08-30 15:34:50.879: E/AndroidRuntime(409):  at com.example.soap_frontend.MainActivity.onCreate(MainActivity.java:40)
08-30 15:34:50.879: E/AndroidRuntime(409):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-30 15:34:50.879: E/AndroidRuntime(409):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-30 15:34:50.879: E/AndroidRuntime(409):  ... 11 more
08-30 15:34:52.978: I/Process(409): Sending signal. PID: 409 SIG: 9

MainActivity.java

package com.example.soap_frontend;

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.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity 
{

private static String NAMESPACE = "http://tempuri.org/";
   private static String METHOD_NAME = "FahrenheitToCelsius";
   private static String SOAP_ACTION = "http://tempuri.org/FahrenheitToCelsius";
   private static String URL = "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL";

   Button btnFar;
   EditText txtFar;

   @Override
   public void onCreate(Bundle savedInstanceState)
   {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main1);

       btnFar = (Button)findViewById(R.id.button1);

       txtFar = (EditText)findViewById(R.id.editText1);

       btnFar.setOnClickListener(new View.OnClickListener()
       {
       public void onClick(View v)
       {

           String b;

         //Initialize soap request + add parameters
         SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);       

         //Use this to add parameters
         request.addProperty("Fahrenheit",txtFar.getText().toString());

         //Declare the version of the SOAP request
         SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

         envelope.setOutputSoapObject(request);
         envelope.dotNet = true;

         try 
         {
             HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

             //this is the actual part that will call the webservice
             androidHttpTransport.call(SOAP_ACTION, envelope);

             // Get the SoapResult from the envelope body.

             SoapPrimitive result = (SoapPrimitive)envelope.getResponse();

             if(result != null)
             {
              //Get the first property and change the label text

                b = result.toString();

                Intent i = new Intent(getApplicationContext(), ResultActivity.class);
                i.putExtra("gotonextpage", b.toString());
                startActivity(i);
              }

             else
             {
               Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_SHORT).show();
             }
        }
        catch (Exception e)
        {
           e.printStackTrace();
           }
         }
       });
   }}

ResultActivity.java

package com.example.soap_frontend;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class ResultActivity extends Activity 
{
    TextView tv;
    String result;

/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main1);

    Bundle extras = getIntent().getExtras();
    if(extras != null)
    {
        result = extras.getString("gotonextpage");
    }
    tv = (TextView)findViewById(R.id.textView_result);
    tv.setText(result);

    }
}

0 个答案:

没有答案