Android 如果(url!=null)不起作用

Android 如果(url!=null)不起作用,android,android-intent,Android,Android Intent,因为我可以做的不同,如果url有信息或没有。因为我做得不好。它不起作用 Bundle bundle = getIntent().getExtras(); String url = bundle.getString("url"); if (url != null) { emVideoView = (EMVideoView)findViewById(R.id.video_play_activity_video_view); emVid

因为我可以做的不同,如果url有信息或没有。因为我做得不好。它不起作用

        Bundle bundle = getIntent().getExtras();
    String url = bundle.getString("url");

    if (url != null) {
        emVideoView = (EMVideoView)findViewById(R.id.video_play_activity_video_view);
        emVideoView.setOnPreparedListener(this);
        //For now we just picked an arbitrary item to play.  More can be found at
        //https://archive.org/details/more_animation
        emVideoView.setVideoURI(Uri.parse(url));
    } else{
        Toast.makeText(getBaseContext(), "Not url found!", Toast.LENGTH_SHORT).show();
        MainActivity.this.finish();
    }
尝试:

这将确保String.Empty值也不存在,这与null字符串不同。换言之:

String s = null;
不同于:

String s = String.Empty;

此外,从捆绑包中检索项目时,还需要一个简单的ifbundle.getStringurl!=null也会有帮助。

您的意思是说,即使url为null值,它也会进入if block?期望的行为是什么,实际的行为是什么?错误:63,20错误:找不到符号方法IsNullOrEmptyString我收到此错误尝试导入com.google.common.base.Strings无效。现在错误:12,30错误:package com.google.common.base不存在。错误:63,20错误:找不到符号方法isNullOrEmptyString您需要将jar添加到项目中。这里有一个很好的操作方法:这个包的git源代码是:
String s = String.Empty;
if(url != null)
  if(!url.isEmpty())