小编The*_*bie的帖子

Android - 类型ID的预期资源

我有这个代码

final static int TITLE_ID = 1;
final static int REVIEW_ID = 2;
Run Code Online (Sandbox Code Playgroud)

现在,我想在我的主类中创建一个新的布局

public View createContent() {
    // create linear layout for the entire view
    LinearLayout layout = new LinearLayout(this);
    layout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    layout.setOrientation(LinearLayout.VERTICAL);

    // create TextView for the title
    TextView titleView = new TextView(this);
    titleView.setId(TITLE_ID);
    titleView.setTextColor(Color.GRAY);
    layout.addView(titleView);

    StarView sv = new StarView(this);
    sv.setId(REVIEW_ID);
    layout.addView(sv);

    return layout;
}
Run Code Online (Sandbox Code Playgroud)

但是当我调用TITLE_ID和REVIEW_ID时,它会给我一个错误

提供错误类型的资源标识符.
例如,在调用Resources.getString(int id)时,您应该传递R.string.something,而不是R.drawable.something.
将错误的常量传递给期望一组特定常量的方法.例如,在调用View#setLayoutDirection时,参数必须是android.view.View.LAYOUT_DIRECTION_LTR或android.view.View.LAYOUT_DIRECTION_RTL.

运行此代码时没有任何问题.我只是想知道它为什么会给我一个错误.任何的想法?

java android esri arcgis

44
推荐指数
3
解决办法
4万
查看次数

标签 统计

android ×1

arcgis ×1

esri ×1

java ×1