Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: incompatible types: Object cannot be converted to ... #123

Open
svedie opened this issue Jan 19, 2019 · 9 comments
Open

error: incompatible types: Object cannot be converted to ... #123

svedie opened this issue Jan 19, 2019 · 9 comments

Comments

@svedie
Copy link

svedie commented Jan 19, 2019

Using Kotlin.

I have defined in my root XML data class an element an annotated it with @element

...
  @Element
  var synchronization: Synchronization?,
...

also I have defined a data class Synchronization

@Xml
data class Synchronization(
  @Attribute
  var type: String?,

  @Attribute
  var autosync: Int?,

  @Attribute
  var revision: String?,

  @PropertyElement
  var url: String?,

  @PropertyElement
  var download: String?,

  @PropertyElement
  var upload: String
)

When Android Studio now compiles everything to send it to the device I get following error:

error: incompatible types: Object cannot be converted to Synchronization
Incompatible types. Required: xxx.Synchronization Found: java.lang.Object

In the TypeAdapter of the main XML file there is following code generated and it looks like there is no cast to Synchronization object like in a list.

    childElementBinders.put("synchronization", new ChildElementBinder<ValueHolder>() {
      @Override
      public void fromXml(XmlReader reader, TikXmlConfig config, ValueHolder value) throws
          IOException {
        value.synchronization = config.getTypeAdapter(Synchronization.class).fromXml(reader, config);
      }
    });

For example a list has the needed cast to an account class:

    childElementBinders.put("account", new ChildElementBinder<ValueHolder>() {
      @Override
      public void fromXml(XmlReader reader, TikXmlConfig config, ValueHolder value) throws
          IOException {
        if (value.accounts == null) {
          value.accounts = new ArrayList<Account>();
        }
        value.accounts.add((Account) config.getTypeAdapter(Account.class).fromXml(reader, config) );
      }
    });

Is this a bug or did I miss something?

@sockeqwe
Copy link
Contributor

sockeqwe commented Jan 19, 2019 via email

@svedie
Copy link
Author

svedie commented Jan 19, 2019

Hi Hannes,

the error is on these lines:

    childElementBinders.put("synchronization", new ChildElementBinder<ValueHolder>() {
      @Override
      public void fromXml(XmlReader reader, TikXmlConfig config, ValueHolder value) throws
          IOException {
--->
        value.synchronization = config.getTypeAdapter(Synchronization.class).fromXml(reader, config);
<---
      }
    });

There is no other information as

error: incompatible types: Object cannot be converted to Synchronization

If I scroll down in the generated TypeConverter to the List Element there is a cast on the object:

    childElementBinders.put("account", new ChildElementBinder<ValueHolder>() {
      @Override
      public void fromXml(XmlReader reader, TikXmlConfig config, ValueHolder value) throws
          IOException {
        if (value.accounts == null) {
          value.accounts = new ArrayList<Account>();
        }
<---
        value.accounts.add((Account) config.getTypeAdapter(Account.class).fromXml(reader, config) );
--->
      }
    });

@sockeqwe
Copy link
Contributor

Hm, interesting. You are right that a cast to Synchronization.class should fix the problem, I am just wondering why the compiler isn't doing that automatically (or isn't smart enough to do that on his own). What version of javac do you run, which jdk and which operation system? Which version of TikXml do you use?

@svedie
Copy link
Author

svedie commented Jan 21, 2019

I use Kotlin:
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

implementation 'com.tickaroo.tikxml:annotation:0.8.13'
implementation 'com.tickaroo.tikxml:core:0.8.15'
implementation 'com.tickaroo.tikxml:converters:0.8.13'
kapt 'com.tickaroo.tikxml:processor:0.8.13'

Win10 and Android Studio 3.3.

If I edit the generated file and let the Android Studio add the cast, the problem is "solved" (the file will be generated next build, so it is just a temporary change).

@sockeqwe
Copy link
Contributor

can you please print the output of the following command in windows command line:
javac -version

@svedie
Copy link
Author

svedie commented Jan 21, 2019

I use Java SDK 1.8.181: javac 1.8.0_181

@svedie
Copy link
Author

svedie commented Mar 16, 2019

Any news on this issue?

@ZsoltSzabo88
Copy link

@svedie
I've also faced your mentioned issue and it has been driving my crazy since Tickaro has seemed to me to be an ideal solution for xml parsing.
I've managed to solve the issue which was caused in my case by the different versioning of dependencies.
I've set the core version to 0.8.15 and the others (annotation, processor) to 0.8.13 because

  1. the newer version of annotation package was missing from the maven repo (0.8.15)
  2. the processor (0.8.15) has a dependency on the missing annotation package.
    That was a big mistake as it unrevaled.
    So the solution is simple, just use version 0.8.13 for every dependency.

@svedie
Copy link
Author

svedie commented Aug 18, 2019

Thank you. I will try it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants