Java 当我给数组赋值时,它显示不兼容的数据类型
我有不兼容的数据类型错误。我可以做些什么来移除它。我在最后一行的[getsubject]处出错,该行的值被指定为tt1。它表明getsubject是不兼容的类型Java 当我给数组赋值时,它显示不兼容的数据类型,java,android,Java,Android,我有不兼容的数据类型错误。我可以做些什么来移除它。我在最后一行的[getsubject]处出错,该行的值被指定为tt1。它表明getsubject是不兼容的类型 //FOR TIMETABLE 1 String[][] tt1=new String[10][10]; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R
//FOR TIMETABLE 1
String[][] tt1=new String[10][10];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_data_entry);
final EditText subject=(EditText)findViewById(R.id.subject);
final EditText professor=(EditText)findViewById(R.id.professor);
add=(Button)findViewById(R.id.add_button);
add.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
//Adding and Displaying subjects
String getsubject=subject.getText().toString();
String getprofessor=professor.getText().toString();
tt1[getsubject][getprofessor]=scan.next();
}
});
您应该使用int-value来访问数组项,但可以使用String。在JAVA中,数组总是将数据存储在特定的索引中,例如
在这里,您将字符串指定为索引,这会导致不兼容类型错误,因此请确保将int值指定给数组索引
欲了解更多信息,请访问
我尝试了放置和索引,错误被消除了。谢谢你的帮助。@HumeraShaikh很高兴帮助很高兴帮助你!快乐编码:
int[] temp = new int[10];
temp[0] = 1;
temp[1] = 2 ......