0

My problem is this:

Double result = SubActivity.this.resultado(SubActivity.this.num1, SubActivity.this.pes1, SubActivity.this.num2, SubActivity.this.pes2, 
    SubActivity.this.num3, SubActivity.this.pes3, 
    SubActivity.this.num4, SubActivity.this.pes4, 
    SubActivity.this.num5, SubActivity.this.pes5);                  

AlertDialog.Builder builder = new AlertDialog.Builder(SubActivity.this);                    
builder.setIcon(R.drawable.ic_launcher);                    
builder.setTitle(R.string.result);                    
builder.setMessage(R.string.n + result);                    
builder.setPositiveButton("OK", null);                    
builder.show();                 
return;

But I got a error:

There is no applicable method to '(double)'

How i can add the string?

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
Crimeiaman
  • 51
  • 7

2 Answers2

0

I believe your problem is that there is an implicit cast from string to double because your function returns a string, but you are storing in it a result of type double.

Your code:

Double result = String functionThatReturnsAString();

You need to use the Double.parseDouble() function for the conversion

Double result = Double.parseDouble(functionThanReturnsAString());
Tony Ruth
  • 1,358
  • 8
  • 19
  • I grab the double in the EditText, the "Double result" are only numbers. – Crimeiaman Oct 12 '15 at 20:16
  • What I mean is that EditText returns a string and there is no implicit cast (Double)string, so you have to use the parseDouble function for the conversion. I believe the other answers are better though because it looks like you only need the string, you are only storing the Double to convert it back to a string later. – Tony Ruth Oct 12 '15 at 20:48
  • I got with other method Tony Ruth, anyway thanks for the answer. – Crimeiaman Oct 13 '15 at 20:36
0

Try -

builder.setMessage(Double.parseDouble(getResources.getString(R.String.n))+ result)+"");

(You may need to tinker a bit to get the string from R.string.n


the reference

Community
  • 1
  • 1
Darpan
  • 5,623
  • 3
  • 48
  • 80