[javac] Compiling 1 source file to C:\xampp\htdocs\pro\appinventor-sources\appinventor\components\build\classes\AndroidRuntime
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] C:\xampp\htdocs\pro\appinventor-sources\appinventor\components\src\com\google\appinventor\components\runtime\FirebaseAuthentication.java:669: error: incompatible types: Object cannot be converted to String
[javac] for (String value : (List) header.getValue()) {
[javac] ^
[javac] C:\xampp\htdocs\pro\appinventor-sources\appinventor\components\src\com\google\appinventor\components\runtime\FirebaseAuthentication.java:676: error: incompatible types: Object cannot be converted to String
[javac] for (String value2 : (List) cookie.getValue()) {
[javac] ^
[javac] 2 errors
[javac] 1 warning
i am trying firebase auth can anyone help me to solve
@ewpatton can you have a look at this
To be clear: You're trying to create a component called FirebaseAuthentication?
It looks like the compiler error is pretty clear. You're trying to set value and value2, which are Strings, to something that can't be converted to a String.
I can't see the rest of the code, but are you sure that the getValue() method evaluates to an Array of String? If not, are you sure java for-each is really what you want there?
I agree with @Susan_Lane here that the compiler is pretty clear. Further, this isn’t even an issue with App Inventor but rather a general lack of understanding of how Java works.
The for-each construct in Java requires type agreement between the variable type on the left side of the :
and the iterable type on the right (either a class that implements the Iterable
interface or an array type) such that the type on the left is equivalent or a superclass of the members of the type on the right. Further, because Iterable
is a generic interface, if it isn’t specified the compiler will infer it to be Iterable<Object>
. Because you cast to the unspecified List
type, the right hand side is considered Iterable<Object>
(because List
implements Iterable
), and String
is not a equal/superclass of Object
. Instead, you would want to cast to List<String>
for this to work. Of course, if getValue()
in this context doesn’t actually return that type, expect this to fail at runtime as it’s an unchecked cast (the compiler will warn you of this).
3 Likes