Question

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();
                }
            }
        });
Was it helpful?

Solution

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

OTHER TIPS

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{

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top