UdhayaBalaji / androidannotations

Automatically exported from code.google.com/p/androidannotations
0 stars 0 forks source link

Error: @EActivity can only be used on an element that extends android.app.Activity #133

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Bug reported by gerrit.brehmer at the end of issue 107. I reproduce it here 
because it is a different issue and shouldn't interfere.

**************

With an Update of my IDE this new feature stops working. I used the Snapshot 
version "2.2-20111013.155547-8" with eclipse 3.7.0 / STS 2.7 / m2e 0.13 and JDK 
1.6_22. Yesterday I updated the IDE to STS 2.8 / eclipse 3.7.1 / m2e 1.0 and 
JDK 1.6_29. I don't know which part causes the problem but now the order of 
annotation processing from the source files has changed and the class which 
depends on the generated BaseActivity_ will be processed first. 

But at this moment the validator could not find the base class "extends 
Activity" and stops the build accordingly. My workaround was to remove the 
check, which produces an compile error: 
"validatorHelper.extendsActivity((TypeElement)element, valid);"

**************

I use the latest 2.2 snapshot (2.2-20111125.112625-8).
I get the same error with running a maven build from the command line 
(@EActivity can only be used on an element that extends android.app.Activity)! 
I think it could be related to the JDK update to 1.6_29. Please can you make a 
test with this version?
Should I open a seperate bug for that?
I believe I also read somewhere that the order the classes will be processed is 
not deterministic.

**************

Original issue reported on code.google.com by py.ricau on 26 Nov 2011 at 4:16

GoogleCodeExporter commented 8 years ago
Let's see if it's your environment :

- If you create a new Android project from Eclipse, and quickly add 
AndroidAnnotations on the created Activity, do you also have that problem ?

However, that's just a check, I think it's probably not related to your 
environment. Please follow these instructions to give us information :

- In Eclipse, open Window > Show View > Error Log. If there is an exception in 
AndroidAnnotation, you will see it. If that's the case, please double click on 
it and paste here the full content of "Exception Stack Trace" field.

- Do you use @EActivity only on BaseActivity, or also on other activities ? 

- I'm not sure I understand the exact nature of the problem : do you have a 
clear "compile error message", or do you get an unexpected error / stacktrace ?

Original comment by py.ricau on 26 Nov 2011 at 4:24

GoogleCodeExporter commented 8 years ago
Hum... I think I just had the very same error.

I created a new abstract CustomAbstractActivity  annotated with @EActivity, and 
let all my activities extend the enhanced class (with a _ afterwards). It 
worked very well.

Then I did a "Project > Clean", and I saw this error on all activities :

@EActivity can only be used on an element that extends android.app.Activity

Here is the reason why :

When we do a "whole build", all the annotations are processed at once. So the 
generated enhanced classes don't exist yet. This means that the type of the 
class the our activity extend is "MissingType" (or something like this). 
Therefore, it cannot determine what is the type hierarchy, and check that it 
extends activity.

To get rid of that error, the only current solution is to stop using abstract 
enhanced activity.

An idea on how we can fix that on AndroidAnnotations :

1) Try to deduce the real abstract class from the enhanced class name (not sure 
it's possible, because in some compilers we may not have access to the package 
name.. maybe checking imports...)
2) Check that the real abstract class holds a @EActivity annotation, and if 
yes, then don't issue any compile error 

Original comment by py.ricau on 27 Nov 2011 at 7:42

GoogleCodeExporter commented 8 years ago

Original comment by py.ricau on 28 Nov 2011 at 7:38

GoogleCodeExporter commented 8 years ago
This issue was closed by revision 9711bea01194.

Original comment by py.ricau on 7 Dec 2011 at 7:46