比较String []和崩溃应用程序

时间:2014-05-14 23:44:02

标签: android string

我有一个大问题......我想检查S1 [1]是否为空。 是动态填充但我想知道它何时满或

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); 

                 }

            }
     });

我的应用程序崩溃了。我试过了:

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

我的logcat在eclipse上不起作用...... :( 如果我删除:

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

我的申请有效...... 你可以帮帮我吗?

如果S1不为空,则有效。 谢谢!

编辑: 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.

1 个答案:

答案 0 :(得分:1)

而不是:

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

这样做:

final String s = S1[1]; // Can be null
if (s == null || s.isEmpty()) {
   ...
}