java - 找不到符号变量activity_main

标签 java android xml android-layout android-studio

我是新人。每当我尝试构建并运行此代码时,都会出现此消息。

这是 XML 代码:

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:orientation="vertical"
tools:context="com.example.android.justjava.MainActivity">

<TextView
    android:id="@+id/quantity_text_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="quantity"
    android:textAllCaps="true"
    android:textSize="16sp"
    android:textColor="@android:color/black"
    android:layout_marginLeft="16dp"
    android:layout_marginTop="16dp"/>

<TextView
    android:id="@+id/zero_text_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="0"
    android:layout_below="@+id/quantity_text_view"
    android:textSize="16sp"
    android:textColor="@android:color/black"
    android:layout_marginLeft="16dp"
    android:layout_marginTop="16dp"/>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="order"
    android:textAllCaps="true"
    android:layout_below="@+id/zero_text_view"
    android:layout_marginLeft="16dp"
    android:layout_marginTop="16dp"
    android:onClick="submitOrder"/>

这是 Java 代码:

/** * IMPORTANT: Add your package below. Package name can be found in the project's AndroidManifest.xml file. * This is the package name our example uses: * * package com.example.android.justjava; * */

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

import static com.example.android.justjava.R.id.quantity_text_view;

/** * This app displays an order form to order coffee. */ public class MainActivity extends AppCompatActivity {

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

/**
 * This method is called when the order button is clicked.
 */
public void submitOrder(View view) {
    display(1);
}

/**
 * This method displays the given quantity value on the screen.
 */
private void display(int number) {
    TextView quantityTextView = (TextView) findViewById(R.id/quantity_text_view);
    quantityTextView.setText("" + number);
} }

这是错误的图片:

/image/tlrUi.png

请帮助我

最佳答案

  1. 检查您的 xml 文件名。
  2. 检查您的进口报表
  3. 再次清理并构建项目。

  4. 如果上述方法不起作用,则删除 R 文件并清理它

关于java - 找不到符号变量activity_main,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44951274/

相关文章:

java - 从 php 代码调用 java 应用程序时使用特定的 jvm 安装

java - 获取属性中的数字作为字符串(java.util.Properties,Android)

php - 如何在 PHP 中读取 iTunes XML 文件

java - GridView 项目剪裁和不同的高度

java - 将字节数组转换为字符串 - java

java - 相当于 mongo 的输出 :reduce option in hadoop

java - android - sleep ()然后绘制

android - 覆盖操作栏被状态栏遮挡

android - 标签不显示 Tablayout + ViewPager

java - Xalan-Java 和 XPath 2.0