【问题标题】:Switch Case statement or its alternate If Condition is not working in android [closed]Switch Case语句或其替代If Condition在android中不起作用[关闭]
【发布时间】:2019-06-17 11:09:33
【问题描述】:

我使用 switch case 进行条件检查。它不工作。这是我的实施方式。

@Override
public void onReceiveNotification(String notificationType, String message, String flag) {
    super.onReceiveNotification(notificationType, message, flag);
    Log.d("tag", "==onReceive Notivation====1===" + notificationType);
    if (notificationType.equalsIgnoreCase("MULTIPART_TYPES"))
    {
        Log.d("tag", "==onReceive Notivation===2====" + notificationType);
    }
    switch (notificationType) {
        case "MULTIPART_TYPES":
            Log.d("tag", "==onReceive Notivation=======" + message);
            break;
    }
}

这是我的日志输出

==onReceive Notivation====1=== MULTIPART_TYPES

但是它正在进入带有尊重字符串消息的方法。但它并没有进入切换或if条件。

【问题讨论】:

  • 你能添加你的日志输出吗?
  • @jbarat,我添加了 log out 。请检查
  • 将 else 条件放在 if 块中,默认放在 switch 中。并检查它是否进入 else 或 default 块。
  • 有一个领先的soace。仔细看。

标签: java android if-statement switch-statement


【解决方案1】:

您的 notificationType 前面有一个空格。 删除它或为您的支票添加修剪。像这样。

if (notificationType.trim().equalsIgnoreCase("MULTIPART_TYPES"))
    {
        Log.d("tag", "==onReceive Notivation===2====" + notificationType);
    }

【讨论】:

    猜你喜欢
    • 2016-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多