0

It is showing cannot resovle R. how i can solve this problem????? if you need xml file to solve problem ,ask me in comment

Please help .................................................................................................................................................................................................................................................................................................................. Here's the java code:

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);
    }

here's the xml file::: ................................................................................................................................................................................................................................................

<?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>
  • 1
    do you see R on your import list? – Nikos Hidalgo Dec 11 '18 at 16:05
  • 4
    Possible duplicate of [R cannot be resolved - Android error](https://stackoverflow.com/questions/885009/r-cannot-be-resolved-android-error) – Murat Karagöz Dec 11 '18 at 16:09
  • i'm new in this type of developing ,so can i know where can i find this import list – Sunay Kundalwal Dec 11 '18 at 17:27
  • At the top of the java class you should see a few import statements. This allows you to use the functionality of other classes in the class you are currently working in. You must therefore import the R package to be used to reference the TextView that you are trying to declare. Try this: Click on the left side of the red "R". Then use your keyboard arrow and click right one time. If the R becomes underlined, you can easy import it by pressing alt + enter on windows or option + enter on mac. – syntakks Dec 11 '18 at 18:58
  • Ok, so I looked at your github project and realized that you should not need to import R when you are dealing with an activity. I would scour over the rest of the project, a small mistake can lead to strange errors that really have nothing to do with the error displayed. Wish I could tell you more, but without the project itself in hand it is hard to say. Goodluck! – syntakks Dec 11 '18 at 19:19
  • @syntakks sir / ma'am, i think you can help me with this code – Sunay Kundalwal Dec 12 '18 at 12:10

3 Answers3

0

This may not be the case for you but worth a shot, sometimes Android studio is glitchy and needs to be closed/ reopened. Also you could try, Build > Clean Project.

syntakks
  • 121
  • 1
  • 6
  • actually i'm studying this from udacity and got this code from git hub .i'm providing its link below: https://gist.github.com/anonymous/6dde8cc012ac94aaf9ea – Sunay Kundalwal Dec 11 '18 at 17:29
  • changed nothing and showing error continuously show error after project clean and restrting the software – Sunay Kundalwal Dec 11 '18 at 18:00
0

Try from android studio menu File -> Invalidate Caches and Restart -> Invalidate and Restart

touhid udoy
  • 4,005
  • 2
  • 18
  • 31
  • Thankyou my problem is solved but can you tell me what was the problem – Sunay Kundalwal Dec 12 '18 at 13:38
  • @SunayKundalwal Some times android studio messes up the pre compiled files, caches, which are generated to make thinks work faster and properly. When you make create the cache files again, it solves the issue by building them again. As the reply solved your issue, you might accept is as the answer :) – touhid udoy Dec 12 '18 at 13:52
0

i'm new in this type of developing ,so can i know where can i find this import list

So i can suggest you to check few things.

  1. Make sure you have installed your targeted build tools. Eg: API 28
  2. Check the package name in your AndroidManifest.xml file. You may have deleted the package name from the manifest file mistakenly.
  3. If none of the above in your case, try to import com.example.android.justjava.R
Julfikar
  • 1,353
  • 2
  • 18
  • 35