Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android

problem with button view and java codes in android app

I can run my app successfully but unfortunately I get an error while I am pressing the button which get me confused. I did the project according to a tutorial and can run the tutorials code successfully but not mine. Well can someone help me to find a solution? :)

Here is the XML code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity">

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

        <ImageView
            android:id="@+id/wallpaper"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingBottom="340dp"
            android:paddingTop="0dp"
            android:src="@drawable/wallpaper" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="270dp">

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

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fontFamily="sans-serif-medium"
                android:text="Barcelona"
                android:textColor="#616161"
                android:textSize="14sp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Goal(s):"
                android:textSize="10sp" />

            <TextView
                android:id="@+id/goalBarcelona"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="0" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Foul(s):" />

            <TextView
                android:id="@+id/foulBarcelona"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="0" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:onClick="oneGoalToBarcelona"
                android:text="Goal: " />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:onClick="oneFoulToBarcelona"
                android:text="Foul: " />
        </LinearLayout>

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

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fontFamily="sans-serif-medium"
                android:text="Real Madrid"
                android:textColor="#616161"
                android:textSize="14sp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Goal(s):"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/goalRealMadrid"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:onClick="increaseGoalByOneRealMadrid"
                android:text="0" />

            <TextView
                android:id="@+id/foul"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Foul(s):" />

            <TextView
                android:id="@+id/foulRealMadrid"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:onClick="oneGoalToRealMadrid"
                android:text="0" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:onClick="addGoalRealMadrid"
                android:text="Goal" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:onClick="addFoulRealMadrid"
                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="10dp"
        android:gravity="center"
        android:onClick="gameOver"
        android:text="Game over" />

</RelativeLayout>

and here I want to show a number when someone click goal for real madrid:

package com.hezarehee.android.courtcenter;

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

public class MainActivity extends AppCompatActivity {

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

int plusOneGoalRealMadrid = 0; // this integer variable will save the number of goal

/**
 * this method will add one goal for real madrid
 */
public void increaseGoalByOneRealMadrid(View v) {
    plusOneGoalRealMadrid = plusOneGoalRealMadrid + 1;
    displayGoalRealMadrid(plusOneGoalRealMadrid);
}

/**
 * this method will show the goal real madrid1
 */
public void displayGoalRealMadrid(int goal) {
    TextView showGoalRM = (TextView) findViewById(R.id.goalRealMadrid);
    showGoalRM.setText(String.valueOf(goal));
}

}

I see that you defined your 2 methods for increaseGoalByOneRealMadrid and displayGoalRealMadrid but I don't see anywhere where you are actually calling either one of these 2 methods. What error message are you getting?