【问题标题】:How to Fix the Following Error: Cannot invoke "String.length()" because "this.inputStr" is null如何修复以下错误:无法调用 \"String.length()\" 因为 \"this.inputStr\" 为空
【发布时间】:2022-10-21 17:34:53
【问题描述】:
/* Returns the count of the user's character.  */ 
public int getUserCharCount(){
inputStr = inputStr;
for (int i = 0; i < inputStr.length(); i++) {
  if (inputStr.charAt(i) == userChar) {
  userCharCount ++;
  }
}
return userCharCount; 

}

默认情况下,main 代码中的 inputStr 为 ""。它应该更新到用户输入。

【问题讨论】:

    标签: string null string-length


    【解决方案1】:

    您可以记录 inputStr 也许用户将其设置为 null

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-03
      • 2021-08-29
      • 1970-01-01
      • 1970-01-01
      • 2022-01-10
      • 2022-12-05
      • 2021-09-05
      相关资源
      最近更新 更多