简体   繁体   中英

Weirdest java issue I've encountered, NoClassDefFoundError due to an Annotation?

I think I hit something rough... let me know your thoughts.

I've been developing for while now an infra project for Android which uses Annotations , which I use to define a couple of things.

Take a look at the following annotation, it should compile, and it does, but when I run it on the device, I get a NoClassDefFoundException.

@Target({FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface ViewIdentifier {

    int viewId() default -1;

    int[] viewIds() default {};

    ViewUI_Action[] listeners() default {};

    boolean forDev() default false;

}

This is THE implementation:

@SuppressWarnings("unused")
@ViewIdentifier(
        listeners = ViewUI_Action.OnClickAsCollection,
        viewIds = {R.id.AccelerometerEngineeringScreen, R.id.RotationVectorEngineeringScreen, R.id.NetworkEngineeringScreen,
                R.id.MagneticEngineeringScreen, R.id.OrientationEngineeringScreen, R.id.GPS_EngineeringScreen, R.id.CallsEngineeringScreen,
                R.id.UpgradeAppButton, R.id.DEV_Action_Button, R.id.FYI_Button})
private View[] modelViews; 

If I remove the ViewIdentifier Annotation, the code compiles, and runs fine, the app starts, but if I return the annotation, the NoClassDefFoundError persists.

This is NOT a clean build issue, I've been very careful before posting this, plus, The missing class file is in the bin/classes, and it does work regardless of clean build when I remove the annotation. I've tried refreshing the workspace rebuilding it, close-open project, restart Eclipse, and other tricks.

The weirdest thing is that if I reverse the parameter of the annotation eg.

@SuppressWarnings("unused")
@ViewIdentifier(
        viewIds = {R.id.AccelerometerEngineeringScreen, R.id.RotationVectorEngineeringScreen, R.id.NetworkEngineeringScreen,
                R.id.MagneticEngineeringScreen, R.id.OrientationEngineeringScreen, R.id.GPS_EngineeringScreen, R.id.CallsEngineeringScreen,
                R.id.UpgradeAppButton, R.id.DEV_Action_Button, R.id.FYI_Button},
        listeners = ViewUI_Action.OnClickAsCollection)
private View[] modelViews; 

I get an Eclipse error saying:

在此处输入图片说明

And Eclipse cannot locate the class containing this field.

So what do you think? Error compiling the class?

Adam.

It seems like the listeners field have array initializer syntax even for an array of size one.

Hope that helps :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM