如果我添加其他活动,为什么活动不起作用?

时间:2016-02-09 13:49:36

标签: java android xml

我需要创建一个应用程序,用于在一些不同的表中注册用户和所有其他详细信息。我创建了一个“注册”页面并且它可以工作,但下一页不起作用,现在注册页面/活动也不起作用......为什么?

NextPage:RegisterBody.java

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class RegisterBody extends AppCompatActivity implements View.OnClickListener {

    Button bNext;
    String[] array = new String[5];

    String email="",password="",name="",surname="",age="";

   // private static final String REGISTER_URL = "http://10.0.2.2/sFitness/RegisterBody.php";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register_body);


        bNext.setOnClickListener(this);

        Bundle b= this.getIntent().getExtras();
        array=b.getStringArray(null);
        name=array[0];
        surname=array[1];
        age=array[2];
        email=array[3];
        password=array[4];
    }

    @Override
    public void onClick(View v) {
        switch(v.getId()){
            case R.id.bNext:
                Toast.makeText(getApplicationContext(), "All ok", Toast.LENGTH_LONG).show();
                break;
        }
    }

}

xml文件:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

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

    <TextView
        android:text="Your body info"
        android:gravity="center|top"
        android:layout_marginBottom="35dp"
        android:layout_marginTop="25dp"
        android:textSize="30dp"
        android:textColor="#C71585"
        android:textStyle="bold"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:text="Waistline: "
        android:textColor="#000000"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"/>

    <EditText
        android:id="@+id/Waist"
        android:inputType="numberDecimal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="25dp"/>

    <TextView
        android:text="Hips: "
        android:textColor="#000000"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"/>

    <EditText
        android:id="@+id/Hips"
        android:inputType="numberDecimal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="25dp"/>

    <TextView
        android:text="Breast: "
        android:textColor="#000000"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"/>

    <EditText
        android:id="@+id/Breast"
        android:inputType="numberDecimal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="25dp"/>

    <TextView
        android:text="Wrist: "
        android:textColor="#000000"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"/>

    <EditText
        android:id="@+id/Wrist"
        android:inputType="numberDecimal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="25dp"/>

    <TextView
        android:text="Weight: "
        android:textColor="#000000"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"/>

    <EditText
        android:id="@+id/Weight"
        android:inputType="numberDecimal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="25dp"/>
    <TextView
        android:text="Height: "
        android:textColor="#000000"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"/>

    <EditText
        android:id="@+id/Height"
        android:inputType="numberDecimal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="25dp"/>


    <Button
        android:id="@+id/bNext"
        android:text="Ok"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>


</ScrollView>

运行应用程序时的结果是:

  

您的申请已停止

logcat的:

enter image description here

1 个答案:

答案 0 :(得分:2)

您正尝试在空按钮上设置单击侦听器。

添加此

bNext = (Button)findViewById(R.id.bNext);

bNext.setOnClickListener(this);