Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

@ItemClick with generic wildcards #722

Closed

Description

@WonderCsabo

If a declare a method like this:

@ItemClick(android.R.id.list)
protected void onListItemClick(Choice<?> item) {

}

The generated class will not compile. Actually it has only one problem: it tries to import Choice<?> instead of Choice.

But if i use an actual template parameter it gets worse. For example Choice<String>. In this case, not just the import goes wrong, but the also method call. The generated method call:

onListItemClick(((String>) parent.getAdapter().getItem(position)));

Activity

  1. yDelouis commented on Sep 11, 2013

    @yDelouis
    Contributor

    Are you using the latest version (3.0-SNAPSHOT) or the 2.7.1 ?
    This has been fixed by the PR #627 in the latest version.

  2. WonderCsabo commented on Sep 11, 2013

    @WonderCsabo
    MemberAuthor

    I'm using 2.7.1. I will try the SNAPSHOT and check.

  3. DayS commented on Sep 11, 2013

    @DayS
    Contributor

    In the meantime (and if you want to stay on 2.7.1), you can fix it with a little trick by using this king of class in your method signature :

    class ChoiceWrapper extends Choice<?> {}

    Or you could also use the raw class :-)

  4. WonderCsabo commented on Sep 11, 2013

    @WonderCsabo
    MemberAuthor

    I just checked the snapshot, and unfortunately it seems to be broken. I got the following error message with @ItemClick, but @Bean also produced a similar one.

    at org.androidannotations.helper.APTCodeModelHelper.typeMirrorToJClass(APTCodeModelHelper.java:97)
    at org.androidannotations.helper.APTCodeModelHelper.typeMirrorToJClass(APTCodeModelHelper.java:89)
    at org.androidannotations.helper.APTCodeModelHelper.typeMirrorToJClass(APTCodeModelHelper.java:73)
    at org.androidannotations.processing.ItemClickProcessor.process(ItemClickProcessor.java:95)
  5. DayS commented on Sep 20, 2013

    @DayS
    Contributor

    I think you had another issue in your code which could messed up these ones. Could you confirm ?

  6. WonderCsabo commented on Sep 20, 2013

    @WonderCsabo
    MemberAuthor

    Actually, i made a little test project. Unfortunately, i deleted it. Now i recreated, but i cannot reproduce the issue. I think this bug can be closed now.

  7. WonderCsabo commented on Nov 18, 2013

    @WonderCsabo
    MemberAuthor

    I'm using the latest SNAPSHOT now, and i am still getting the error with @ItemClick generic type parameters.

  8. WonderCsabo commented on Dec 9, 2013

    @WonderCsabo
    MemberAuthor

    I am still getting this error. I just used the same parameter with a @Background annotated method and i got the following message:

    java.lang.NullPointerException
    at org.androidannotations.helper.APTCodeModelHelper.typeMirrorToJClass(APTCodeModelHelper.java:105)
    at org.androidannotations.helper.APTCodeModelHelper.typeMirrorToJClass(APTCodeModelHelper.java:97)
    at org.androidannotations.helper.APTCodeModelHelper.typeMirrorToJClass(APTCodeModelHelper.java:81)
    at org.androidannotations.helper.APTCodeModelHelper.overrideAnnotatedMethod(APTCodeModelHelper.java:128)
    at org.androidannotations.processing.BackgroundProcessor.process(BackgroundProcessor.java:58)
  9. WonderCsabo commented on Dec 29, 2013

    @WonderCsabo
    MemberAuthor

    I checked this again, with two versions. With the brand new stable 3.0 and the latest 3.1-SNAPSHOT. Unfortunetaly i still got the same issue with both.

    Stacktrace: java.lang.NullPointerException
        at org.androidannotations.helper.APTCodeModelHelper.typeMirrorToJClass(APTCodeModelHelper.java:92)
        at org.androidannotations.helper.APTCodeModelHelper.typeMirrorToJClass(APTCodeModelHelper.java:84)
        at org.androidannotations.helper.APTCodeModelHelper.typeMirrorToJClass(APTCodeModelHelper.java:68)
        at org.androidannotations.handler.ItemClickHandler.processParameters(ItemClickHandler.java:85)
        at org.androidannotations.handler.AbstractListenerHandler.process(AbstractListenerHandler.java:105)
        at org.androidannotations.handler.AbstractListenerHandler.process(AbstractListenerHandler.java:50)
        at org.androidannotations.process.ModelProcessor.processThrowing(ModelProcessor.java:163)
        at org.androidannotations.process.ModelProcessor.process(ModelProcessor.java:147)
        at org.androidannotations.AndroidAnnotationProcessor.processAnnotations(AndroidAnnotationProcessor.java:252)
        at org.androidannotations.AndroidAnnotationProcessor.processThrowing(AndroidAnnotationProcessor.java:194)
        at org.androidannotations.AndroidAnnotationProcessor.process(AndroidAnnotationProcessor.java:122)

    Actually, it got a little bit weirder... I did not get a compile error at all, but the class did not get generated because of this fatal exception. bin/androidannotations.log contains the information, but is this intentional? AA should definitely raise a compile error here, for example the developer can think that everything is OK, starts the app, and it crashes because the generated class does not exists.

    I created a little test project, @DayS or @yDelouis could you check it out?

  10. DayS commented on Dec 29, 2013

    @DayS
    Contributor

    Damn.. I'll check that ASAP.
    I added a custom logger to write in a file AND show compilation warnings/errors. So, you should have been notified about this.
    I'll keep you updated

  11. WonderCsabo commented on Dec 29, 2013

    @WonderCsabo
    MemberAuthor

    OK, if you think i can assist you in any way feel free to contact me.

  12. DayS commented on Dec 29, 2013

    @DayS
    Contributor

    Ho. Got it for the silent exception... I made a small mistake in Logger.error() call from handleException() method. I fixed it.

    About the exception itself, I'll debug this today.

  13. DayS commented on Dec 29, 2013

    @DayS
    Contributor

    This should work now in 3.1-SNAPSHOT.

    In the meantime you should use <? extends Objects> or <Objet>instead of <?>.

  14. WonderCsabo commented on Dec 29, 2013

    @WonderCsabo
    MemberAuthor

    I can confirm that this bug is finally solved using the latest SNAPSHOT build. Thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions