【问题标题】:Annotation Attribute not accepting my variable注释属性不接受我的变量
【发布时间】:2012-07-20 22:16:48
【问题描述】:

我现在阅读了很多关于这方面的内容,并且我发现了如何使用新的 ADT 的 switch 语句来赋予常量表达式的示例,但没有提到关于 @Inject 的所有内容。

这是我有问题的代码的示例。

 import roboguice.inject.InjectView;
 public abstract class YpListActivity extends GuiceListActivity 

     @InjectView(R.id.btnSearch)
     Button btnSearch;
     @InjectView(R.id.btnSpeech)
     View btnSpeech;
     @InjectView(R.id.etWhat)
     EditText etWhat;
     @InjectView(R.id.etWhere)
     EditText etWhere;
     @InjectView(R.id.tvIn)
     TextView tvIn;
     @InjectView(R.id.tvLocation)
     TextView tvLocation;
     @InjectView(R.id.tvCustom)
     private ToggleButton tvCustom;
     @InjectView(R.id.infoButton)
     private ImageView iconButton;

每次我尝试使用 @injectView(R.id.*) 之类的东西时,eclipse 都会抛出错误:

“注解属性InjectView.value的值必须是常量表达式。”

我什至尝试将其更改为:

     private static final int btnsrch = new Integer(R.id.btnSearch);

     @InjectView(btnsrch )
     TableRow btnSearch ;

“btnsrch”怎么不是常量表达式??

有人知道如何解决这个问题吗?

【问题讨论】:

标签: android eclipse google-api


【解决方案1】:

删除“private”,它应该可以正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-11
    • 1970-01-01
    • 2016-03-23
    • 2019-03-24
    • 1970-01-01
    • 2019-04-24
    • 1970-01-01
    相关资源
    最近更新 更多