edittext
每当我单击按钮时,我的应用程序总是崩溃...按钮从null pointer exception
. 第一个问题:如何检查是否editText
为空?我已经尝试过.equals("")
,.equals(null)
与匹配相同,.lenght == 0
其次,当我尝试为我的listActivity
班级调用意图时,我得到一个处理错误。(未找到活动。没有要处理的活动。)我会给你我的 onClickListener
点击监听器
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
searchInEnglish = rSearchEnglish.isChecked();
searchInDovahzul = rSearchDovahzul.isChecked();
searchBox = (EditText) findViewById(R.id.tvSearch);
if (searchBox.getText().toString().equals("")){
if (searchInEnglish) {
int counter = 0;
for (int i = 0; i < englishArray.length; i++) {
if (englishArray[i].contains(searchBox.getText())) {
counter++;
Intent search = new Intent(
"net.fernandezgodinho.pedro.dovahzuldictionary.SEARCHLIST");
startActivity(search);
}
}
setFinalSearch(searchResultsEnglish);
}
if (searchInDovahzul = true) {
int counter = 0;
for (int i = 0; i < dovahzulArray.length; i++) {
if (dovahzulArray[i].contains(searchBox.getText())) {
counter++;
Intent search = new Intent(
"net.fernandezgodinho.pedro.dovahzuldictionary.SEARCHLIST");
startActivity(search);
}
}
}
} else {
Toast.makeText(MainActivity.this, "Please use at least two characters", Toast.LENGTH_LONG).show();
}
}
});