Question

I have a big problem... I want check if S1[1] is empty. is populated dynamically but I want to know when it is full or when it is empty

public class MainActivity extends FragmentActivity  {
public String[] S1 = new String[200];
....

btnArrivi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                 try {

                     if(S1[1].equals(""))
                     Toast.makeText(MainActivity.this, S1[1]
                            , Toast.LENGTH_LONG).show();

                    .....
                     Fragment a = Check(S1); 

                 }

            }
     });

My application crashes. I have tried :

f(S1[1].isEmpty(""))

My logcat doesn't work on eclipse... :( If I delete:

if(S1[1].equals(""))
Toast.makeText(MainActivity.this, S1[1], Toast.LENGTH_LONG).show();

My application works... can you help me please?

If S1 isn't empty, works. Thank you!

EDIT: logcat:

    05-09 07:35:48.655: E/chromium(3421): [ERROR:chrome_browser_main_android.cc(130)] Not implemented reached in void RecordBreakpadStatusUMA(MetricsService*)
05-09 07:35:49.460: E/Nova.Workspace(2867): The Hotseat screen must be >= 0 and < 1 (was 1); skipping child
05-09 07:35:49.465: E/Nova.Workspace(2867): The Hotseat screen must be >= 0 and < 1 (was 2); skipping child
05-09 07:35:50.630: E/RestStorages(2827): using folders=/storage/extSdCard/Musica/
05-09 07:35:51.150: E/FbInjectorInitializer(3510): Multi-binding Key[type=com.facebook.common.init.INeedInit, annotation=[none]] wasn't declared.
Was it helpful?

Solution

Instead of this:

if (S1[1].equals("")) {
   ...
}

Do this:

final String s = S1[1]; // Can be null
if (s == null || s.isEmpty()) {
   ...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top