我是新人。每当我尝试构建并运行此代码时,都会出现此消息。
这是 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); } }
这是错误的图片:
请帮助我
最佳答案
- 检查您的 xml 文件名。
- 检查您的进口报表
再次清理并构建项目。
如果上述方法不起作用,则删除 R 文件并清理它
关于java - 找不到符号变量activity_main,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44951274/