类型不匹配:不能转换从字符串到R.string [英] Type mismatch: cannot convert from String to R.string
问题描述
我是新所以请原谅我的原始的问题,我真的没有得到这一点。我只是建立在我的主要活动数组,而做一个教程,我得到一个错误
I am new so forgive my primitive question, I am really not getting this. I am simply creating this array on my main activity while doing a tutorial and I get an error
package com.TaskReminder;
import android.R.string;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
public class ReminderListActivity extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reminder_list);
string[] items = new string[]{"aa","bb"};
ArrayAdapter<string> adapter = new ArrayAdapter<string>(this,R.layout.reminder_row,R.id.text1,items);
setListAdapter(adapter);
}
和我的字符串数组上的错误是:
and the error on my string array is :
在该行多个标记
- 行断点:ReminderListActivity [行:14] -
的onCreate(捆绑)
Multiple markers at this line - Line breakpoint:ReminderListActivity [line: 14] - onCreate(Bundle)
- 类型不匹配:不能从字符串转换成R.string
什么也正是发生在这里?
what's exactly happening here?
推荐答案
易修复,String类型必须大写。
Easy fix, the String type needs to be capitalized.
string[] items = new string[]{"aa","bb"};
ArrayAdapter<string> adapter = new ArrayAdapter<string>(this,R.layout.reminder_row,R.id.text1,items);
变成了:
String[] items = new String[]{"aa","bb"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.reminder_row,R.id.text1,items);
@gt_ebuddy是正确的,以及,删除此行:
@gt_ebuddy is right as well, remove this line:
进口android.R.string;
import android.R.string;
使用<大骨节病>键Crtl + Shift + O 骨节病>是自动导入类最简单的方法,但它有时会导致你引入歧途当它试图从导入你的包的R档东西。
Using Crtl+Shift+O is the simplest way to import classes automatically, but it sometimes leads you astray when it tries to import anything from your package's R file.
这篇关于类型不匹配:不能转换从字符串到R.string的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!