-2

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();
                }
            }
        });
Vipul Purohit
  • 9,807
  • 6
  • 53
  • 76
Fowlron
  • 99
  • 1
  • 11
  • Try to start your activity like `Intent search = new Intent( CurrentActivity.this, NewActivity.class);` `startActivity(search);` and see if error persist. – Shobhit Puri Aug 28 '13 at 12:00
  • 1
    paste your logcat stacktrace – Nargis Aug 28 '13 at 12:03
  • Did you add the intent to the intent-filter of the corresponding activity? – Sambuca Aug 28 '13 at 12:04
  • OH i forgot to add the intent-filter to the manifest... Sorry for the error, im a begginer on android. Thanks a lot for your help everyone. Now ill just correct the if statement block, and them, teoricly, it should work. Thanks everyone for your help again. – Fowlron Aug 28 '13 at 20:07

2 Answers2

1

To check EditText is null or not, write below code

EditText editText=(EditText)findviewById(R.id.myEditText);

if(TextUtils.isEmpty(editText.getText())){

     // show msg or whatever you want to do on empty text case    

}else{

}
Ripal Tamboli
  • 562
  • 1
  • 4
  • 16
1

It seems like you are calling an activity from another application.

Have you added the <intent-filter> to another activity in the application manifest ?

Step #1: Add an <intent-filter> to the second activity with a custom action:

<intent-filter>
  <action android:name="com.testapp.ws.XYZ"/>
  <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

Step #2: Start that activity using an appropriate Intent:

startActivity(new Intent("com.testapp.ws.XYZ"));

See this for further explanations - https://stackoverflow.com/a/10961409/826657

Community
  • 1
  • 1
Rachit Mishra
  • 6,101
  • 4
  • 30
  • 51