找不到解决方案??它表明无法解决R

时间:2018-12-11 16:03:24

标签: android

显示无法反抗R。 我如何解决这个问题? 如果您需要xml文件来解决问题,请在注释中提问

请帮助  ................................................... ................................................... ................................................... ................................................... ................................................... ................................................... ...... 这是Java代码:

package com.example.android.justjava;


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

import java.text.NumberFormat;

/**
 * This app displays an order form to order coffee.
 */
public class MainActivity extends AppCompatActivity {
    int  quantity = 0;

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

    /**
     * This method is called when the order button is clicked.
     */
    public void submitOrder(View view) {
        int price= quantity*16;
       String priceMessage="total:" + (quantity*16) ;
              priceMessage=priceMessage +"\nThank You!";
             displayMessage(priceMessage);

    }

    /**
     * This method displays the given text on the screen.
     */
    private void displayMessage(String message) {
        TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
        priceTextView.setText(message);
    }

    public void increase(View view) {
        quantity = quantity + 1;

displayPrice(quantity*16);
        display(quantity);
    }

    public void decrease(View view) {

            quantity = quantity - 1;
        displayPrice(quantity*16);
        display(quantity);
    }
    /**
     * 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);
    }

    /**
     * This method displays the given price on the screen.
     */
    private void displayPrice(int number) {
        TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
        priceTextView.setText(NumberFormat.getCurrencyInstance().format(number);
    }

这是xml文件::: ................................................... ................................................... ................................................... ................................................... ........................................

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    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="match_parent"
        android:background="@drawable/w"
        android:orientation="vertical"
        >


        <TextView
            android:id="@+id/txt1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="20dp"

            android:text="Welcome to Ordering Menu"
            android:textColor="@android:color/white"
            android:textSize="25sp"
            app:fontFamily="@font/crafty_girls" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_height="wrap_content"
            android:orientation="horizontal">


            <ImageView
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_marginLeft="20dp"
                android:src="@drawable/cappo"/>
            <Button
                android:id="@+id/btn2"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:textSize="30sp"
                android:layout_marginLeft="50dp"
                android:layout_marginTop="20dp"
                android:onClick="increase"
                android:text="+"
                android:textColor="@android:color/black"
                android:background="@android:color/white" />



            <TextView

                android:id="@+id/quantity_text_view"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="20dp"
                android:text="0"
                android:textSize="20sp"

                android:textColor="@android:color/white" />

            <Button
                android:id="@+id/btn3"
                android:layout_width="50dp"
                android:textColor="@android:color/black"
                android:background="@android:color/white"
                android:layout_height="50dp"
                android:textBold="true"
                android:layout_marginLeft="10dp"
                 android:layout_marginTop="20dp"
                android:onClick="decrease"
                android:textSize="30sp"
                android:text="-" />


        </LinearLayout>


        <TextView

            android:id="@+id/kk"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="170dp"
            android:text="Price" />

        <TextView
            android:id="@+id/price_text_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="10dp"
            android:text="$0"
            android:textColor="#000000" />


        <Button
            android:id="@+id/btn1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="15dp"
            android:onClick="submitOrder"
            android:text="ORDER" />


    </LinearLayout>

</android.support.constraint.ConstraintLayout>

3 个答案:

答案 0 :(得分:0)

对您来说可能不是这种情况,但值得一试,有时Android studio会出现故障,需要关闭/重新打开。您也可以尝试Build> Clean Project。

答案 1 :(得分:0)

尝试从android studio菜单File -> Invalidate Caches and Restart -> Invalidate and Restart

答案 2 :(得分:0)

  

我是这种开发中的新手,所以我可以在哪里找到此导入列表

所以我可以建议您检查几件事。

  1. 确保已安装目标构建工具。例如:API 28
  2. 在您的AndroidManifest.xml文件中检查包名称。您可能错误地从清单文件中删除了程序包名称。
  3. 如果上述情况都不满足,请尝试import com.example.android.justjava.R