Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tabhost应用程序在android/eclipse中意外关闭_Android_Eclipse_Android Tabhost - Fatal编程技术网

Tabhost应用程序在android/eclipse中意外关闭

Tabhost应用程序在android/eclipse中意外关闭,android,eclipse,android-tabhost,Android,Eclipse,Android Tabhost,现在,我试图显示从一个页面到tabhost的第一个选项卡(其中包含android上的两个选项卡)消费Web服务的结果 但是模拟器在运行后,它只是显示了您的应用程序”意外停止了如何解决这个问题 Demo.webservicecactivity.java public class Demo_webserviceActivity extends Activity { /** Called when the activity is first created. */ private static

现在,我试图显示从一个页面到tabhost的第一个选项卡(其中包含android上的两个选项卡)消费Web服务的结果

但是模拟器在运行后,它只是显示了
您的应用程序”意外停止了

如何解决这个问题

Demo.webservicecactivity.java

public class Demo_webserviceActivity extends Activity
{
/** Called when the activity is first created. */

   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";


EditText txtFar;
Button btnFar;
SharedPreferences sharedPreferences;

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main1);

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

    btnFar.setOnClickListener(new View.OnClickListener() {

   public void onClick(View v){
   SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);

   request.addProperty("Fahrenheit",txtFar.getText().toString());

   SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

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

   try
   {
       HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

       androidHttpTransport.call(SOAP_ACTION, envelope);

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

if(result != null)
{
    sharedPreferences=PreferenceManager.getDefaultSharedPreferences(Demo_webserviceActivity.this);
    Editor editor1 = sharedPreferences.edit();
    editor1.remove("answer");
    editor1.commit();

    sharedPreferences=PreferenceManager.getDefaultSharedPreferences(Demo_webserviceActivity.this);
    Editor editor = sharedPreferences.edit();
    Log.i("set value",""+txtFar.getText().toString());
    editor.putString("answer",txtFar.getText().toString());
    editor.commit();
   }
   else
   {
    Toast.makeText(getApplicationContext(), "oops! empty!...",        Toast.LENGTH_SHORT).show();
    }
   }    
       catch(Exception e)
       {
        e.printStackTrace();
    }
            }
        });
        }
    }

Logcat:

06-18 12:22:59.902: D/AndroidRuntime(482): Shutting down VM
06-18 12:22:59.922: W/dalvikvm(482): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
06-18 12:22:59.932: E/AndroidRuntime(482): FATAL EXCEPTION: main
06-18 12:22:59.932: E/AndroidRuntime(482): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.demo.webser/com.demo.webser.Demo_webserviceActivity}: java.lang.NullPointerException
06-18 12:22:59.932: E/AndroidRuntime(482):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-18 12:22:59.932: E/AndroidRuntime(482):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-18 12:22:59.932: E/AndroidRuntime(482):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-18 12:22:59.932: E/AndroidRuntime(482):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-18 12:22:59.932: E/AndroidRuntime(482):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-18 12:22:59.932: E/AndroidRuntime(482):  at android.os.Looper.loop(Looper.java:123)
06-18 12:22:59.932: E/AndroidRuntime(482):  at android.app.ActivityThread.main(ActivityThread.java:4627)
06-18 12:22:59.932: E/AndroidRuntime(482):  at java.lang.reflect.Method.invokeNative(Native Method)
06-18 12:22:59.932: E/AndroidRuntime(482):  at java.lang.reflect.Method.invoke(Method.java:521)
06-18 12:22:59.932: E/AndroidRuntime(482):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-18 12:22:59.932: E/AndroidRuntime(482):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-18 12:22:59.932: E/AndroidRuntime(482):  at dalvik.system.NativeStart.main(Native Method)
06-18 12:22:59.932: E/AndroidRuntime(482): Caused by: java.lang.NullPointerException
06-18 12:22:59.932: E/AndroidRuntime(482):  at com.demo.webser.Demo_webserviceActivity.onCreate(Demo_webserviceActivity.java:45)
06-18 12:22:59.932: E/AndroidRuntime(482):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-18 12:22:59.932: E/AndroidRuntime(482):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-18 12:22:59.932: E/AndroidRuntime(482):  ... 11 more
main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >



<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ems="10" >

    <requestFocus />
</EditText>

<Button
    android:id="@+id/btnFar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Get result" />

</LinearLayou>

感谢您的帮助!

从外观上看,问题可能出在这里:

6-18 12:22:59.932:E/AndroidRuntime(482):由以下原因引起: java.lang.NullPointerException 06-18 12:22:59.932: E/AndroidRuntime(482):在 com.demo.webser.demo\uWebServiceActivity.onCreate(demo\uWebServiceActivity.java:45)

看看你的代码,我猜第45行是(因为没有给出行号):

btnFar.setOnClickListener(新视图.OnClickListener(){


您确定
btn
不为空吗?

演示Web服务活动中的第45行在哪里?演示Web服务活动中的第45行出现未捕获的异常错误。请告诉我们该行的情况。这是第45行btnFar.setOnClickListener(新视图。OnClickListener(){您是否从main1.xml获取了正确的btnFar id?是的,我有。为了便于参考,我已经包含了我的main1.xml…请稍等@独自一人晚上
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TabHost
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </TabWidget>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <LinearLayout
                android:id="@+id/tab1"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >
            </LinearLayout>

            <LinearLayout
                android:id="@+id/tab2"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >
            </LinearLayout>

            <LinearLayout
                android:id="@+id/tab3"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >
            </LinearLayout>
        </FrameLayout>
    </LinearLayout>
</TabHost>
06-18 12:22:59.902: D/AndroidRuntime(482): Shutting down VM
06-18 12:22:59.922: W/dalvikvm(482): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
06-18 12:22:59.932: E/AndroidRuntime(482): FATAL EXCEPTION: main
06-18 12:22:59.932: E/AndroidRuntime(482): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.demo.webser/com.demo.webser.Demo_webserviceActivity}: java.lang.NullPointerException
06-18 12:22:59.932: E/AndroidRuntime(482):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-18 12:22:59.932: E/AndroidRuntime(482):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-18 12:22:59.932: E/AndroidRuntime(482):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-18 12:22:59.932: E/AndroidRuntime(482):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-18 12:22:59.932: E/AndroidRuntime(482):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-18 12:22:59.932: E/AndroidRuntime(482):  at android.os.Looper.loop(Looper.java:123)
06-18 12:22:59.932: E/AndroidRuntime(482):  at android.app.ActivityThread.main(ActivityThread.java:4627)
06-18 12:22:59.932: E/AndroidRuntime(482):  at java.lang.reflect.Method.invokeNative(Native Method)
06-18 12:22:59.932: E/AndroidRuntime(482):  at java.lang.reflect.Method.invoke(Method.java:521)
06-18 12:22:59.932: E/AndroidRuntime(482):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-18 12:22:59.932: E/AndroidRuntime(482):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-18 12:22:59.932: E/AndroidRuntime(482):  at dalvik.system.NativeStart.main(Native Method)
06-18 12:22:59.932: E/AndroidRuntime(482): Caused by: java.lang.NullPointerException
06-18 12:22:59.932: E/AndroidRuntime(482):  at com.demo.webser.Demo_webserviceActivity.onCreate(Demo_webserviceActivity.java:45)
06-18 12:22:59.932: E/AndroidRuntime(482):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-18 12:22:59.932: E/AndroidRuntime(482):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-18 12:22:59.932: E/AndroidRuntime(482):  ... 11 more
06-18 12:52:27.612: W/KeyCharacterMap(509): No keyboard for id 0
06-18 12:52:27.612: W/KeyCharacterMap(509): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
06-18 12:52:31.523: I/set value(509): 56