My App Always crash whenever I click on a button... the button gets text from an edittext
, and i believe that that is why i have a null pointer exception
. First question: how can i check if the editText
is empty? I already tried .equals("")
, .equals(null)
, same with matches, and .lenght == 0
Second, when i try to call the intent for my listActivity
class i get a handling error. (Activity not found. No activity to handle.)
Ill give you my onClickListener
ON CLICK LISTENER
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();
}
}
});