简体   繁体   English

为什么我对字符串的空检查不起作用?

[英]Why is my null check against my string not working?

Alright here we go. 好了,我们开始吧。

I am probably asking the most popular question on here and I'm freaking seasoned dev. 我可能会问这里最流行的问题,而且我很老练。

Basically I am comparing if a String is null. 基本上我在比较String是否为null。 IT IS NULL But sadly, it is for some reason bypassing my if and going straight for my else. 它为空,但可悲的是,由于某种原因,它绕过了我的if,直接进入了else。

I feel ashamed and guilty for asking this oh so simple question but I am at a loss. 我问这个如此简单的问题感到as愧和内,但我很茫然。

What am I missing? 我想念什么?

Relevant Code: 相关代码:

  Log.i(TAG,"mBeforeId..." + mBeforeId);
            if(mBeforeId == null){
                Log.i(TAG,"mBeforeId INSIDE IF..." + mBeforeId);
                 Toast.makeText(getActivity(),"These are no current listings before these.",Toast.LENGTH_SHORT).show();
            }else{
                getSubReddit(mSubReddit, Constants.HOT_CATEGORY, mBeforeId, null);
            }

LogCat: LogCat:

 12-31 13:34:04.139  10383-10383/com.android.finalproject.tubbsreddit I/SubRedditFragment﹕ mBeforeId...null

As you can clearly see, It is saying mBeforeId is null but it refuses to go to my if and makes pals with my else. 正如您可以清楚地看到的那样,这是说mBeforeId为null,但它拒绝去找我,并与我的else交了朋友。

GAR. GAR

In Android Log statements, if you try to print a String which has null value, it throws an exception. 在Android Log语句中,如果您尝试打印具有null值的String,它将引发异常。 This might be the reason why you are seeing this unexpected behavior. 这可能是您看到此意外行为的原因。

Try to remove the log cat statements if the value is null. 如果该值为空,请尝试删除log cat语句。 It might work. 它可能会起作用。 Give a try 试一下

Fixed it. 修复。

Basically 基本上

mBeforeId was "null", not null . mBeforeId为“ null”,不为null It was the actual string "null". 它是实际的字符串“ null”。

Don't you just love programming? 您不只是喜欢编程吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM