Android ...我的应用程序无法启动?

时间:2018-10-22 02:30:45

标签: java android xml android-studio android-layout

所以,我正在尝试开发一个应用程序,使用户能够跟踪两个不同球队踢足球的得分和犯规次数

android:layout_height="match_parent"
tools:context=".MainActivity">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif-medium"
            android:gravity="center_horizontal"
            android:padding="4dp"
            android:paddingBottom="16dp"
            android:paddingTop="16dp"
            android:text="Team A"
            android:textColor="#616161"
            android:textSize="14sp" />

        <TextView
            android:id="@+id/team_a_goal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif-light"
            android:gravity="center_horizontal"
            android:padding="4dp"
            android:paddingBottom="24dp"
            android:paddingLeft="24dp"
            android:paddingRight="24dp"
            android:text="0"
            android:textColor="#000000"
            android:textSize="56sp" />


        <TextView
            android:id="@+id/team_a_foul"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif-light"
            android:gravity="center_horizontal"
            android:padding="4dp"
            android:paddingBottom="24dp"
            android:paddingLeft="24dp"
            android:paddingRight="24dp"
            android:text="0"
            android:textColor="#000000"
            android:textSize="56sp" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="8dp"
            android:layout_marginBottom="8dp"
            android:onClick="addGoalForTeamA"
            android:text="GOAL" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="8dp"
            android:layout_marginBottom="8dp"
            android:onClick="addFoulForTeamA"
            android:text="FOUL" />

    </LinearLayout>

    <view
        android:layout_width="1dp"
        android:layout_height="match_parent"
        android:background="@android:color/darker_gray" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif-medium"
            android:gravity="center_horizontal"
            android:padding="4dp"
            android:paddingBottom="16dp"
            android:paddingTop="16dp"
            android:text="Team B"
            android:textColor="#616161"
            android:textSize="14sp" />

        <TextView
            android:id="@+id/team_b_goal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif-light"
            android:gravity="center_horizontal"
            android:padding="4dp"
            android:paddingBottom="24dp"
            android:paddingLeft="24dp"
            android:paddingRight="24dp"
            android:text="0"
            android:textColor="#000000"
            android:textSize="56sp" />


        <TextView
            android:id="@+id/team_b_foul"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif-light"
            android:gravity="center_horizontal"
            android:padding="4dp"
            android:paddingBottom="24dp"
            android:paddingLeft="24dp"
            android:paddingRight="24dp"
            android:text="0"
            android:textColor="#000000"
            android:textSize="56sp" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="8dp"
            android:layout_marginBottom="8dp"
            android:onClick="addGoalForTeamB"
            android:text="GOAL" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="8dp"
            android:layout_marginBottom="8dp"
            android:onClick="addFoulForTeamB"
            android:text="FOUL" />

    </LinearLayout>

</LinearLayout>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="32dp"
    android:onClick="Reset"
    android:text="Reset" />

和Java代码

package com.example.android.scorekeeper;

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

public class MainActivity extends AppCompatActivity {

int goalTeamA = 0;
int foulTeamA = 0;
int goalTeamB = 0;
int foulTeamB = 0;

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

}

public void addGoalForTeamA(View view) {
    goalTeamA = +1;
    displayGoalTeamA(goalTeamA);
}

public void addFoulForTeamA(View view) {
    foulTeamA = +1;
    displayFoulTeamA(foulTeamA);
}


public void addGoalForTeamB(View view) {
    goalTeamB = +1;
    displayGoalTeamB(goalTeamB);
}

public void addFoulForTeamB(View view) {
    foulTeamB = +1;
    displayFoulTeamB(foulTeamB);
}


public void Reset(View view) {
    goalTeamA = 0;
    foulTeamA = 0;
    goalTeamB = 0;
    foulTeamB = 0;
    displayGoalTeamA(goalTeamA);
    displayFoulTeamA(foulTeamA);
    displayGoalTeamB(goalTeamB);
    displayFoulTeamB(foulTeamB);
}


public void displayGoalTeamA(int score) {
    TextView scoreView = findViewById(R.id.team_a_goal);
    scoreView.setText(String.valueOf(score));
}

public void displayFoulTeamA(int score) {
    TextView scoreView = findViewById(R.id.team_a_foul);
    scoreView.setText(String.valueOf(score));
}

public void displayGoalTeamB(int score) {
    TextView scoreView = findViewById(R.id.team_b_goal);
    scoreView.setText(String.valueOf(score));
}

public void displayFoulTeamB(int score) {
    TextView scoreView = findViewById(R.id.team_b_foul);
    scoreView.setText(String.valueOf(score));
} }

代码对我来说似乎很好,并且Android Studio没有报告任何错误,但是没有在我的android上启动

1 个答案:

答案 0 :(得分:0)

确保您已将活动添加到清单文件中

    <activity
        android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>