如何修复以下错误:无法调用'string.length()"因为“ this.inputstr”是无效的

发布于 2025-02-10 03:53:38 字数 316 浏览 1 评论 0原文

/* 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; 

}

默认情况下,Inputstr在主代码中为“”。它应该更新给用户输入。

/* 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; 

}

By default, inputStr is "" in the Main code. It should be updating to the user input.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

世界等同你 2025-02-17 03:53:38

您可以记录Inputstr
也许用户将其设置为null。
另外,您可以在操作前检查您的变量是否为null。
很难说出了什么问题,因为您不提供容纳您的变量的类,而不是提供创建和修改的类别的方式。
可能是您使用null创建新的,可能是用户更改为null的值

You can log inputStr
maybe user set it to null.
also you may check if your variable is null before action.
It hard to say what wrong because you not provide class that hold your variable, and not provide way that class are created and modified.
may be you create new one with null, may be user change value to null

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文