-3

enter image description here

Hello, here's my issue : I keep having an error telling me that the types are incompatible even though my "R.id.total_akylux" is a Number(Decimal) in the XML file, and the result is given in decimal. I don't really understand why do i keep having this error. If someone could help me, it'd be really useful. Thank you

Hitesh
  • 3,449
  • 8
  • 39
  • 57
Oxy180
  • 11
  • 3
  • 7
    **1.** Post your code here, don't link to an image. **2.** `R.id.` is generated by Android for various resources and should not be modified. **3.** I think you're using `R.id` in a completely wrong way. **4.** `R.id.` have `int` values. **5.** You're trying to assign a `double` value to an `int` value, which can't be done automatically by Java – QBrute Oct 27 '16 at 09:59
  • You are using the **id**s of your resources, not your resources themselves. – Phantômaxx Oct 27 '16 at 10:12

2 Answers2

3

First of all: Mind QBrutes comment and re-think your concept.

You are trying to assign a double to an int, this is exactly what the error tells you. Now that int you are using isn't even your number but the ID of your resource. If you really want to store an int in your resources, follow this answer: https://stackoverflow.com/a/19297523/2694254

Regarding your error
Double can't be assigned to int without some manual casting. If you are confused by the int/double casting stuff:

int numberInt = 1;
double numberDouble = 1.8;

//what you are trying to do:
numberInt = numberDouble;

//what you could do:
numberInt = (int) numberDouble; //numberInt is now 1

//with rounding:
numberInt = (int) Math.round(numberDouble); //numberInt is now 2

Also, you could store a float in xml instead of int: https://stackoverflow.com/a/20120240/2694254

You could also store the double as String, but that would require even more casting.

Community
  • 1
  • 1
tritop
  • 1,655
  • 2
  • 18
  • 30
0

First of all, I'd like to thank you to take time to answer me even though i'm new to this language. I understand what you're saying to me so i started changing my code like this

double prix = 15.90;
double m2 = (longueur_akylux*largeur_akylux)/100;
double total = prix*m2* quantite;


@Override

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.akylux);
}

@SuppressWarnings("unused")
public void calcul_akylux(View v){
    TextView t = (TextView) findViewById(R.id.total_akylux);
    t.setText(total);
}

So, if i create a Number(Decimal) in the XML , it won't wait for a double ? How can i do so this Number is a decimal ?

Thank you

Oxy180
  • 11
  • 3