so is this correct or not please tell
Ohhhhh I know why now, an Object cannot be passed to Integer.parseInt()
ā¦ To fix it, just change that piece to Integer.parseInt(itemInList.toString())
. Or you can change the lines to the new linesā¦
list.toArray()
can be switched to list.toStringArray()
, BUT Object itemInList
must be changed to String itemInList
ā¦ Nothing else must be changedā¦ OR,
Just change Integer.parseInt(itemInList)
to Integer.parseInt(itemInList.toString())
as I said firstā¦ Whichever seems easier to you.
@luv.ak.tech below would be proper.
import com.google.appinventor.components.runtime.util.YailList;
import java.lang.NumberFormatException;
import java.util.Arrays;
import java.util.List;
...
// Place this inside of your extension class
@SimpleFunction
public int LoopOverList(YailList list) {
List listOfNumbers = Arrays.asList(list.toStringArray());
int finalResult = 0;
for (String itemInList : listOfNumbers) {
try {
finalResult += Integer.parseInt(itemInList);
} catch(NumberFormatException nfe) {
// Not a number
nfe.printStackTrace();
}
}
return finalResult;
}
Thank you for pointing that out @Srrazmi!
sorry i am asking too many questions
because i started making extensions just yesterday
what does this do?
You also have multiple accounts on the same ip adress. You are only allowed to have one on the community. Which one should i delete?
It basically logs the error to system logsā¦ I think, as my knowledge goes with printStackTrace
and system logs. Though it would only occur if an item was not a number! You can remove it if youād like, just donāt break;
the list.
if we need to make the same thing just do mutiply instead of plus shall we need to do like this?
If you want to multiply finalResult
by Integer.parseInt(itemInList)
then yes. But it wouldnāt really work because finalResult = 0
and well all know that 0 multiplied by another number still equals 0, so youād probably want to change finalResult
to finalResult = 1
.
help me there is an error coming
/projects/goldv2/appinventor-sources/appinventor/build.xml:35: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:372: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/components/build.xml:141: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:118: Compile failed; see the compiler error output for details.
That isnāt an error , you might share the whole error.
ok i will share
Buildfile: /projects/goldv2/appinventor-sources/appinventor/build.xml
extensions:
clean:
init:
common_CommonUtils:
init:
CommonUtils:
common_CommonVersion:
init:
CommonVersion:
[exec] Result: 128
[exec] Result: 128
CopyToRunLibDir:
components_AndroidRuntime:
init:
CommonConstants:
[javac] Compiling 6 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/CommonConstants
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] 1 warning
HtmlEntities:
common_CommonVersion:
init:
CommonVersion:
[exec] Result: 128
[exec] Result: 128
AndroidRuntime:
[javac] Compiling 332 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AndroidRuntime
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/contact2niraj/Maths_extension/Maths_extension.java:58: error: cannot find symbol
[javac] public int LoopOverList(YailList list) {
[javac] ^
[javac] symbol: class YailList
[javac] location: class Maths_extension
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/contact2niraj/Maths_extension/Maths_extension.java:75: error: cannot find symbol
[javac] public int LoopOverList(YailList list) {
[javac] ^
[javac] symbol: class YailList
[javac] location: class Maths_extension
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/contact2niraj/Maths_extension/Maths_extension.java:62: error: incompatible types: Object cannot be converted to String
[javac] for (String itemInList : listOfNumbers) {
[javac] ^
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/contact2niraj/Maths_extension/Maths_extension.java:79: error: incompatible types: Object cannot be converted to String
[javac] for (String itemInList : listOfNumbers) {
[javac] ^
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 4 errors
[javac] 1 warning
BUILD FAILED
/projects/goldv2/appinventor-sources/appinventor/build.xml:35: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:372: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/components/build.xml:141: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:118: Compile failed; see the compiler error output for details.
Total time: 7 seconds
lList list) {
[javac] ^
[javac] symbol: class YailList
[javac] location: class Maths_extension
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/contact2niraj/Maths_extension/Maths_extension.java:75: error: cannot find symbol
[javac] public int LoopOverList(YailList list) {
[javac] ^
[javac] symbol: class YailList
[javac] location: class Maths_extension
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/contact2niraj/Maths_extension/Maths_extension.java:62: error: incompatible types: Object cannot be converted to String
[javac] for (String itemInList : listOfNumbers) {
[javac] ^
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/contact2niraj/Maths_extension/Maths_extension.java:79: error: incompatible types: Object cannot be converted to String
[javac] for (String itemInList : listOfNumbers) {
[javac] ^
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 4 errors
[javac] 1 warning
BUILD FAILED
/projects/goldv2/appinventor-sources/appinventor/build.xml:35: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:372: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/components/build.xml:141: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:118: Compile failed; see the compiler error output for details.
Total time: 7 seconds
Do you have import com.google.appinventor.components.runtime.util.YailList;
?
sorry i forgot to add that
After you add the class, make sure the function looks like that.
it looks like this
Are you ok?
Oop, they went offline
its still showing error