Android 如何使用选项卡活动实现按钮

Android 如何使用选项卡活动实现按钮,android,android-intent,Android,Android Intent,我有一个tab活动,然后在其中一个活动中,我想放置一个按钮,以转到另一个活动。但是,当我对按钮进行编码时,没有出现错误,但启动应用程序时,按钮会崩溃,错误代码为: 11-14 12:50:43.783:E/AndroidRuntime10933:java.lang.RuntimeException:无法启动活动组件信息{com.dist.distguide/com.dist.distguide.MainActivity}:java.lang.NullPointerException 但是,当我删

我有一个tab活动,然后在其中一个活动中,我想放置一个按钮,以转到另一个活动。但是,当我对按钮进行编码时,没有出现错误,但启动应用程序时,按钮会崩溃,错误代码为:

11-14 12:50:43.783:E/AndroidRuntime10933:java.lang.RuntimeException:无法启动活动组件信息{com.dist.distguide/com.dist.distguide.MainActivity}:java.lang.NullPointerException

但是,当我删除按钮编码的应用程序启动罚款

这是我的XML文件:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/logo1">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp">

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

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp" >

        <Button
            android:id="@+id/Distancecalc"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Distance Calculator" />

        <Button
            android:id="@+id/Distance"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Distance Calculator" />

    </FrameLayout>

  </LinearLayout>
 </TabHost>
我做错了什么? 请帮忙! 谢谢你的改变

Button add = (Button)findViewById(R.id.Distance1);

您的按钮id是Distancecalc。您正试图用distance 1初始化它。

更改

Button add = (Button)findViewById(R.id.Distance1);


您的按钮id是Distancecalc。您正试图用Distance1对其进行初始化。

还有一件事很抱歉,我已在中放置了另一个按钮,但在应用程序中启动时它不会显示。好像按钮不见了。我有什么想法或链接可以纠正这个问题吗?我试过了,但它似乎只是把按钮放在第一个按钮后面,我更新了我的问题对不起,还有一件事,我放了另一个按钮,但在应用程序启动时它没有显示。好像按钮不见了。有什么想法或链接我可以去纠正这一点吗?我已经尝试了,但它似乎只是把按钮后面的第一个按钮,我已经更新了我的问题
Button add = (Button)findViewById(R.id.Distancecalc);