运行自己编写的app出问题 1C

因为第一次自己编写android,我找了老半天也没有找到问题,在AVD上运行,总是显示“Uunfotunately。。。。“
以下是代码
xml:
<?xml version="1.0" encoding="utf-8"?>
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true">
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.example.a29185.test_app.MainActivity">

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/title"
    android:layout_marginTop="@dimen/activity_vertical_margin"
    android:gravity="center"
    android:textStyle="bold"
    android:textSize="20sp"
    android:text="QUESTION" />
<TextView
    style="@style/MainText"
    android:id="@+id/one"
    android:text="1. What's your name:"
    />
<EditText
    android:id="@+id/name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textImeMultiLine"
    android:hint="Input your name"
    android:singleLine="false"/>
/>
<TextView
    style="@style/MainText"
    android:id="@+id/two"
    android:text="2. 2 + 2 = 3"
    />
<RadioGroup
    android:id="@+id/radioGroup"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
<RadioButton
    android:id="@+id/yes"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Yes"
    android:layout_margin="5sp"
    />
<RadioButton
    android:id="@+id/no"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="No"
    android:layout_margin="5sp"
    />
</RadioGroup>
<TextView
style="@style/MainText"
android:id="@+id/three"
android:text="3. 1 + 1 ="
/>
<CheckBox
    android:id="@+id/three0"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="0"
    android:padding="10sp"/>
<CheckBox
    android:id="@+id/three1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="1"
    android:padding="10sp"/>
<CheckBox
    android:id="@+id/three2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="2"
    android:padding="10sp"/>
<TextView
    style="@style/MainText"
    android:id="@+id/four"
    android:text="4. What's your goal:"
    />
<EditText
    android:id="@+id/goal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="Please input your goal"
    android:singleLine="false"/>
<TextView
    style="@style/MainText"
    android:id="@+id/five"
    android:text="5. Are you like your family ?"
    />
<RadioGroup
    android:id="@+id/radioGroup1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
<RadioButton
    android:id="@+id/yes2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Yes"
    android:layout_margin="5sp"
    />
<RadioButton
    android:id="@+id/no2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="No"
    android:layout_margin="5sp"
    android:padding="10sp"
    />
</RadioGroup>
<Button
    android:id="@+id/submit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="submit"
    android:textAllCaps="false"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="50dp"
    android:onClick="getscore"
    />


java:

package com.example.a29185.test_app;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
int score = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

public void getscore (int scor){
    //judge first question.
    EditText editText1 = (EditText)findViewById(R.id.name);
   int a = Integer.valueOf(editText1.getText().toString());
    if (a==0) score+=1;
    else score +=0;
    //judge second question.
    RadioGroup sex = (RadioGroup) findViewById (R.id.radioGroup);
    if(sex.getCheckedRadioButtonId()==R.id.yes)
        score +=1;
    else score +=0;
    //judge third question.
    CheckBox checkThree = (CheckBox)findViewById(R.id.three2);
    if (checkThree.isChecked())
        score+=1;
    else score +=0;
    //judge fourth question.
    EditText editText = (EditText)findViewById(R.id.goal);
    int b = Integer.valueOf(editText.getText().toString());
    if (b==0) score+=1;
    else score +=0;
    //judge fifth question.
    RadioGroup happy = (RadioGroup) findViewById (R.id.radioGroup1);
    if(happy.getCheckedRadioButtonId()==R.id.yes2)
        score +=1;
    else score +=0;
             display(score);
}
public void display(int score){
    Toast.makeText(MainActivity.this,"The full score is 5.\nYou get "+ score+".",Toast.LENGTH_SHORT).show();
}

}

请大家帮下忙,我找了好多遍都不知道为啥,代码没问题。只要点到submit按钮,就会出现“Unfortunately什么什么的“完了退出去,本身是可以进入界面的。

1个回答

请提供完整的错误信息截图

WangZuoChuan
rain_flow 应该是activity没有加到AndroidManifest.xml中
大约 3 年之前 回复
codibear
codibear 就是点击按钮,他就终止运行,弹出去。
大约 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!