Java Android按钮不会打印出字符串消息

Java Android按钮不会打印出字符串消息,java,android,Java,Android,我曾尝试搜索android开发者,但没有成功 我的onClick方法不打印任何消息。我想把我的文字从。。。到然而,当我点击它时,什么也没有发生 爪哇 XML 您的代码在我的设备中工作正常 请尝试清理项目并再次运行代码 建造->清洁 然后运行代码按钮点击前是否显示“我很饿”?确切的代码对我来说运行良好尝试清理项目然后重新运行项目如何“清理”项目,这没有意义?构建->清理项目,然后运行使其工作的代码!谢谢除息的 public class MainActivity extends AppCompatA

我曾尝试搜索android开发者,但没有成功

我的onClick方法不打印任何消息。我想把我的文字从。。。到然而,当我点击它时,什么也没有发生

爪哇

XML


您的代码在我的设备中工作正常 请尝试清理项目并再次运行代码

建造->清洁


然后运行代码

按钮点击前是否显示“我很饿”?确切的代码对我来说运行良好尝试清理项目然后重新运行项目如何“清理”项目,这没有意义?构建->清理项目,然后运行使其工作的代码!谢谢除息的
public class MainActivity extends AppCompatActivity {

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

    /**
     * This method is called when the Cookie button is clicked.
     */
    public void eatCookie(View view) {
        display("I'm so full");
    }

    /**
     * This method displays the given quantity value on the screen.
     */
    private void display(String status) {
        TextView statusTextView = (TextView) findViewById(
                R.id.status_text_view);
        statusTextView.setText("" + status);
    }
}
<LinearLayout 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"
    android:background="#B388FF"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/android_cookie_image_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:scaleType="centerCrop"
        android:src="@drawable/before_cookie" />

    <TextView
        android:id="@+id/status_text_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginTop="16dp"
        android:text="I'm so hungry"
        android:textColor="@android:color/white"
        android:textSize="34sp" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:text="EAT COOKIE"
        android:onClick="eatCookie"/>

</LinearLayout>