String Can Not Be Converted To Int

Hello Koders I am building a extension. but i have faced a error. which is String cannot be converted to int.

Build Log :-

> [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/vedangsolaskar2018/NumConvert/NumConvert.java:41: error: incompatible types: String cannot be converted to int
[javac]       return "1k+";
[javac]              ^

Code :-

@SimpleFunction(description = “convert number”)
public int ConvertViews(int number){
// 1
int a = 999;
int b = 1099;

if(number < b && number > a){
return “1k+”;
}
}

You are returning String while you have declared your method to return int.

1 Like

How Can I Fix it Now

Declare your method to return String.

You Mean public String

Yes.
Change int to String.
Also for questions about working with the App Inventor sources, the best place is to ask in the App Inventor Open Source forum

Copied from Taifun

1 Like

Actually I Am Using Appybuilder Code Editor

Now This Error Is Solved But A Faced Another

[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/vedangsolaskar2018/NumConvert/NumConvert.java:43: error: missing return statement
[javac] }
[javac] ^

You are returning value only from if condition but what about else condition.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.