我正在尝试使用this card library为我试图构建的安卓应用程序的UI,但我遇到了一些问题。
作者has this guide for using the library with an existing Eclipse project,这是我一直遵循的,但我得到了多个错误。
我将该库作为“现有项目”导入到Eclipse中的Import options下,并将该项目包含在现有项目的构建路径中,但我一直收到有关缺少方法(特别是在constructor中指定的getContext()参数)的错误,即使在导入整个库之后也是如此。
下面是我的代码片段:
import it.gmariotti.cardslib.library.internal.Card;
import it.gmariotti.cardslib.library.internal.CardHeader;
public class MainActivity extends Activity {
Card card = new Card(getContext());
CardHeader header = new CardHeader(getContext());
card.addCardHeader(header);
CardView cardView = (CardView) getActivity().findViewById(R.id.carddemo);
cardView.setCard(card);对于我的代码片段中的每一行,我都得到了以下错误:
The method getContext() is undefined for the type MainActivity
The method getContext() is undefined for the type MainActivity
Multiple markers at this line
- Syntax error on token(s), misplaced construct(s)
- Syntax error on token "header", VariableDeclaratorId expected after
Multiple markers at this line
- CardView cannot be resolved to a type
- CardView cannot be resolved to a type
- The method getActivity() is undefined for the type
MainActivity
Multiple markers at this line
- Syntax error on token "card", VariableDeclaratorId expected after
this token
- Syntax error on token(s), misplaced construct(s)我知道这是一个非常具体的问题,但我希望我能在这里得到一个答案!
发布于 2014-01-14 09:57:16
你的错误与Cardslib无关。卡片构造接受当前活动的上下文。在Android中没有getContext()函数。正确的函数是getBaseContext()。
有两种方式发送它。
Card card = new Card(getBaseContext());或
Card card = new Card(this);https://stackoverflow.com/questions/20874455
复制相似问题