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.

Generated classes: cannot be resolved to a type #257

Description

@pflammertsma

I have a project containing several Activities and Fragments that are generated using AndroidAnnotations. It worked great until I began to notice strange errors:

FragmentActiveAction_ cannot be resolved to a type StartActivity.java /myproject/src/com/myproject/activities line 55 Java Problem
FragmentZoneList_ cannot be resolved to a type StartActivity.java /myproject/src/com/myproject/activities line 215 Java Problem
FragmentZoneList_ cannot be resolved to a type StartActivity.java /myproject/src/com/myproject/activities line 215 Java Problem
The import com.myproject.activities.ZoneMapActivity_ cannot be resolved FragmentZoneList.java /myproject/src/com/myproject/fragments line 22 Java Problem
The import com.myproject.fragments.FragmentActiveAction_ cannot be resolved StartActivity.java /myproject/src/com/myproject/activities line 20 Java Problem
The import com.myproject.fragments.FragmentZoneList_ cannot be resolved StartActivity.java /myproject/src/com/myproject/activities line 22 Java Problem
ZoneMapActivity_ cannot be resolved to a type FragmentZoneList.java /myproject/src/com/myproject/fragments line 77 Java Problem

Oddly, I can very easily fix these problems by simply deleting the import declaration and having it automatically added again (through Eclipse's organize imports save action). My project then compiles and runs without any problems.

When cleaning the project, the same errors return. The generated java files are nevertheless present, Eclipse just doesn't "see" them. Here's Eclipse's log output after cleaning the project:

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2012-06-29 15:21:09.895
!MESSAGE Starting AndroidAnnotations annotation processing

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2012-06-29 15:21:09.897
!MESSAGE Dummy source file: file:///C:/Users/Paul/workspace/myproject/.apt_generated/dummy1340976069897.java

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2012-06-29 15:21:09.898
!MESSAGE AndroidManifest.xml file found: C:\Users\Paul\workspace\myproject\AndroidManifest.xml

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2012-06-29 15:21:09.960
!MESSAGE Number of files generated by AndroidAnnotations: 13

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2012-06-29 15:21:09.961
!MESSAGE Generating source file: com.myproject.rest.ApiClient_

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2012-06-29 15:21:09.967
!MESSAGE Generating source file: com.myproject.ActionApp_

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2012-06-29 15:21:09.970
!MESSAGE Generating source file: com.myproject.fragments.FragmentActiveAction_

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2012-06-29 15:21:09.975
!MESSAGE Generating source file: com.myproject.fragments.FragmentListDialog_

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2012-06-29 15:21:09.980
!MESSAGE Generating source file: com.myproject.fragments.FragmentMap_

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2012-06-29 15:21:09.983
!MESSAGE Generating source file: com.myproject.fragments.FragmentActionOne_

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2012-06-29 15:21:09.989
!MESSAGE Generating source file: com.myproject.fragments.FragmentZoneInfoDialog_

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2012-06-29 15:21:09.992
!MESSAGE Generating source file: com.myproject.fragments.FragmentZoneList_

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2012-06-29 15:21:09.995
!MESSAGE Generating source file: com.myproject.activities.AccountActivity_

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2012-06-29 15:21:10.000
!MESSAGE Generating source file: com.myproject.activities.HistoryActivity_

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2012-06-29 15:21:10.028
!MESSAGE Generating source file: com.myproject.activities.LoginActivity_

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2012-06-29 15:21:10.067
!MESSAGE Generating source file: com.myproject.activities.StartActivity_

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2012-06-29 15:21:10.071
!MESSAGE Generating source file: com.myproject.activities.ZoneMapActivity_

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2012-06-29 15:21:10.075
!MESSAGE Time measurements: [Whole Processing = 178 ms], [Generate Sources = 115 ms], [Process Annotations = 33 ms], [Find R Classes = 18 ms], [Validate Annotations = 8 ms], [Extract Manifest = 4 ms], [Extract Annotations = 0 ms],

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2012-06-29 15:21:10.082
!MESSAGE Time measurements: [Whole Processing = 0 ms],

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2012-06-29 15:21:10.084
!MESSAGE Time measurements: [Whole Processing = 0 ms],

I am using ADT 20 with platform tools 12. There are some other annotation libraries being used in the project: ORMLite, Simple Framework and Spring.

Activity

  1. pyricau commented on Jun 29, 2012

    @pyricau
    Contributor

    I have noticed that kind of issue too. Clearly, Eclipse has some problems with import resolving, when you clean the project. It won't happen if you use fully qualified names and no imports. Weird. We need to dive into eclipse to understand what happens.

  2. pflammertsma commented on Jun 29, 2012

    @pflammertsma
    Author

    That's a good suggestion: I'll used fully qualified names. In the meantime, I'll keep my fingers crossed that you find some miracle solution.

    Incidentally, I'm still using Eclipse Indigo. Does the problem still occur in Juno?

  3. pyricau commented on Jul 2, 2012

    @pyricau
    Contributor

    I don't know, I'm still using Indigo. We need to find out.

  4. pflammertsma commented on Jul 2, 2012

    @pflammertsma
    Author

    I've been using Juno since Thursday, and literally as I'm typing this, the same problem occurred. Too bad!

  5. vvakame commented on Jul 4, 2012

    @vvakame

    I have same problem. Eclipse can't resolved FooBarFragment_ .
    Eclipse version is 3.7.2 and 4.2 at My MacBookAir.
    But same environment other one (MacBookPro) is works good...
    I can't isolate the problem.

  6. pflammertsma commented on Jul 5, 2012

    @pflammertsma
    Author

    vvakame, does the problem appear on your MBP when you clean the project? This seems to consistently raise the issue within my project.

  7. pyricau commented on Jul 5, 2012

    @pyricau
    Contributor

    @vvakame At least it's good to know that you have an environment where it works right. Do you have a different java version ?

  8. pyricau commented on Jul 6, 2012

    @pyricau
    Contributor

    It would really be great if you could isolate the problem :)

  9. pyricau commented on Jul 7, 2012

    @pyricau
    Contributor

    I have some good news: the bug haven't been fixed yet, but at least we can isolate it. This kept bugging me, so I took the time to slim down an existing project until I could find the exact conditions to reproduce it.

    https://bugs.eclipse.org/bugs/show_bug.cgi?id=350378#c6

    This clearly isn't an Android bug, and probably not an AndroidAnnotations bug. It seems to be Eclipse related. Let's see if that can be solved.

  10. pflammertsma commented on Jul 9, 2012

    @pflammertsma
    Author

    Awesome that you could figure out where it's coming from and you could provide a minimum working example. I've subscribed to the issue and keep my fingers crossed!

  11. pyricau commented on Aug 24, 2012

    @pyricau
    Contributor

    :)

    I ended up creating a new issue in Eclipse, Juno related : https://bugs.eclipse.org/bugs/show_bug.cgi?id=387956 . The use case even related to AndroidAnnotations anymore.

    Meanwhile, to prevent this, you can :

    • Remove the need for imports on generated files, by putting the files in the same package or using qualified names
    • Stop using annotations with constant references in classes where you import generated files. Either by relying on the element name convention, or by using the new resName() annotation parameter.
  12. pyricau commented on Sep 1, 2012

    @pyricau
    Contributor

    Actually, the simplest way may be to do an import of the whole package for the generated class :)

    Instead of import com.company.MyBean_;, just do import com.company.*;

    I'm trying to move things forward on the Eclipse side, but they have a lot of things to do.

    I have updated the FAQ with this issue.

  13. mathieuboniface commented on Nov 24, 2012

    @mathieuboniface
    Contributor

    This has been reported on the eclipse side. Not related to an AA bug.

  14. philipp-f-lang commented on Sep 30, 2013

    @philipp-f-lang

    To work with fully qualified class names does not work for me. I always get a "NoClassDefFoundError" when i try to start an activity with "de....MainActivity_.intent(this).start()". Any suggestions?

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions