Android studio 该应用程序没有';行不通

Android studio 该应用程序没有';行不通,android-studio,android-studio-3.0,Android Studio,Android Studio 3.0,我正在开发我的CourtCounter应用程序,但我有3个bug 1) 当您尝试为Peat添加点时,它不起作用。所有的积分都归玛尔塔所有 2) 当我按下重置按钮时,整个应用程序正在重新启动(只是它正在停止)。我认为应该重新开始结果 3) 背景中的图像-如您所见,它已被删除。看起来不太好。我想我只需要使用尺寸合适的图片,专用于手机? ****代码** **主要活动**** <?xml version="1.0" encoding="utf-8"?> <RelativeLayo

我正在开发我的CourtCounter应用程序,但我有3个bug 1) 当您尝试为Peat添加点时,它不起作用。所有的积分都归玛尔塔所有 2) 当我按下重置按钮时,整个应用程序正在重新启动(只是它正在停止)。我认为应该重新开始结果 3) 背景中的图像-如您所见,它已被删除。看起来不太好。我想我只需要使用尺寸合适的图片,专用于手机?

****代码**

**主要活动****

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@drawable/a"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dip">




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



        <LinearLayout
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical"
            tools:context="com.example.majka.courtcounter.MainActivity">



            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:padding="4dp"
                android:text="MARTA'S TEAM"
                android:textColor="#FF040510"
                android:background="#c2c2c6"
                android:textSize="20sp"
                android:textStyle="bold"
                android:fontFamily="sans-serif"
                android:layout_marginTop="16dp"
                android:layout_marginBottom="16dp"
                android:layout_marginRight="2dp"
                android:elevation="2dp"/>

            <TextView
                android:id="@+id/martas_team_score"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:padding="4dp"
                android:text="0"
                android:textSize="80sp"
                android:paddingBottom="24dp"
                android:paddingTop="16dp"
                android:textColor="#000000"/>


            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:onClick="addThreeToTeamA"
                android:text="+3 points"
                android:layout_marginLeft="24dp"
                android:layout_marginRight="24dp"
                android:layout_marginBottom="8dp"
                android:background="#3F51B5"
                android:textColor="#ECEFF1"
                android:layout_marginTop="13dp"/>

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:onClick="addTwoToTeamA"
                android:text="+2 points"
                android:layout_marginLeft="24dp"
                android:layout_marginRight="24dp"
                android:layout_marginBottom="8dp"
                android:background="#3F51B5"
                android:textColor="#ECEFF1"/>

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:onClick="addOneToTeamA"
                android:text="Free Throw"
                android:layout_marginLeft="24dp"
                android:layout_marginRight="24dp"
                android:layout_marginBottom="8dp"
                android:background="#3F51B5"
                android:textColor="#ECEFF1"/>

        </LinearLayout>

        <LinearLayout xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical"
            tools:context="com.example.majka.courtcounter.MainActivity">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:padding="4dp"
                android:text=" PEAT'S TEAM"
                android:textColor="#040510"
                android:background="#c2c2c6"
                android:textSize="20sp"
                android:textStyle="bold"
                android:fontFamily="sans-serif"
                android:layout_marginTop="16dp"
                android:layout_marginBottom="16dp"
                android:layout_marginLeft="2dp"
                android:elevation="2dp"/>

            <TextView
                android:id="@+id/team_2_scores"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:padding="4dp"
                android:text="0"
                android:textSize="80sp"
                android:paddingBottom="24dp"
                android:paddingTop="16dp"
                android:textColor="#000000"/>


            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:onClick="addThreeToTeamA"
                android:text="+3 points"
                android:layout_marginLeft="24dp"
                android:layout_marginRight="24dp"
                android:layout_marginBottom="8dp"
                android:background="#673AB7"
                android:textColor="#ECEFF1"
                android:layout_marginTop="13dp" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:onClick="addTwoToTeamA"
                android:text="+2 points"
                android:layout_marginLeft="24dp"
                android:layout_marginRight="24dp"
                android:layout_marginBottom="8dp"
                android:background="#673AB7"
                android:textColor="#ECEFF1"/>

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:onClick="addOneToTeamA"
                android:text="Free Throw"
                android:layout_marginLeft="24dp"
                android:layout_marginRight="24dp"
                android:layout_marginBottom="8dp"
                android:background="#673AB7"
                android:textColor="#ECEFF1"/>

        </LinearLayout>

    </LinearLayout>

     <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="RESET"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:onClick="ResetScore"
        android:background="#B0BEC5"
        android:layout_marginBottom="16dp"
        android:fontFamily="sans-serif"/>


</RelativeLayout>
有人能帮我吗? 我不认为这个错误会变成代码。我不知道为什么它不起作用。

1)在Peat团队的按钮中,
onClick
属性使用了团队A的方法

2) 重置按钮的
onClick
属性引用了一个名为
ResetScore
的方法,但您在代码中定义的方法名为
ResetScore
(注意小写的“r”)。这将导致你的应用程序崩溃


3) 您可能希望使用不同的图像,或者,如果您切换到使用
android:src
属性,您可以使用该属性控制图像的缩放。

hi。谢谢你的提示。我使用了所有这些,但现在应用程序也不工作了:(@MartaOniszk当你从Android Studio运行应用程序时,你在Logcat窗口中看到了什么错误消息?它工作了。我检查了Logcat窗口。我再次检查了整个代码,它工作了。:-)嗨!欢迎来到Stackoverflow。请发布问题更新,如对原始问题的编辑,而不是作为答案,因为它们不是答案。我已经为此对他们进行了标记。此外,最好提供一个完整的代码,而不是所有的代码,因为社区更容易检查它。因此,请相应地编辑您的问题。谢谢
package com.example.majka.courtcounter;

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

public class MainActivity extends AppCompatActivity {
    int scoreTeamA = 0;
    int scoreTeamB = 0;

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

    public void addThreeToTeamA (View v ) {
        scoreTeamA = scoreTeamA + 3;
        displayForTeamA(scoreTeamA);

    }

    public void addTwoToTeamA (View v ) {
        scoreTeamA = scoreTeamA + 2;
        displayForTeamA(scoreTeamA);

    }

    public void addOneToTeamA (View v ) {
        scoreTeamA = scoreTeamA + 1;
        displayForTeamA(scoreTeamA);

    }

    public void addOneForTeamB(View v) {
        scoreTeamB = scoreTeamB + 1;
        displayForTeamB(scoreTeamB);
    }

    /**
     * Increase the score for Team B by 2 points.
     */
    public void addTwoForTeamB(View v) {
        scoreTeamB = scoreTeamB + 2;
        displayForTeamB(scoreTeamB);
    }

    /**
     * Increase the score for Team B by 3 points.
     */
    public void addThreeForTeamB(View v) {
        scoreTeamB = scoreTeamB + 3;
        displayForTeamB(scoreTeamB);
    }


    /**
     * Displays the given score for Team A.
     */
    public void displayForTeamA(int score) {
        TextView scoreView = (TextView) findViewById(R.id.martas_team_score);
        scoreView.setText(String.valueOf(score));
    }

    /**
     * Displays the given score for Team B.
     */
    public void displayForTeamB(int score) {
        TextView scoreView = (TextView) findViewById(R.id.peats_team_score);
        scoreView.setText(String.valueOf(score));
    }

    public void resetScore(View v) {
        scoreTeamA = 0;
        scoreTeamB = 0;
        displayForTeamA(scoreTeamA);
        displayForTeamB(scoreTeamB);
    }
}